With an addon, should I register for a single module or individual classes?

While browsing through the included addons in Blender’s default scripts folder I noticed that a lot of the addons simply register at the bottom like this, with no concern for registering individual classes.

def register():
    bpy.utils.register_module(__name__)


def unregister():
    bpy.utils.unregister_module(__name__)


if __name__ == "__main__":
    register()

Up until now I had been registering my classes like this:


classes = [myClass, mySuperCoolClass, myOtherClass, someOtherClass]
    
def register():
    for c in classes:
        bpy.utils.register_class(c)


def unregister():
    for c in classes:
        bpy.utils.unregister_class(c)


if __name__ == "__main__":
    register()

The addons included in Blender certainly declare new classes but just use the module register way of doing things. Trying both ways seems to work, and also I can test run the script from the text editor both ways, and the addon still works. Which way is the best? What’s the difference?

register_module() and unregister_module() are utility functions, which use the _bpy module to register all classes of your script or module:

def register_module(module, verbose=False):
    if verbose:
        print("bpy.utils.register_module(%r): ..." % module)
    cls = None
    for cls in _bpy_module_classes(module, is_registered=False):
        if verbose:
            print("    %r" % cls)
        try:
            register_class(cls)
        except:
            print("bpy.utils.register_module(): "
                  "failed to registering class %r" % cls)
            import traceback
            traceback.print_exc()
    if verbose:
        print("done.
")
    if cls is None:
        raise Exception("register_module(%r): defines no classes" % module)

So it’s partially Python, and partially C (_bpy module) opposed to the pure Python way you do with for c in classes: …

You should use (un)register_module(), 'cause it makes your life easier, and never use register_class() again (and not in conjunction with register_module!)

Hahaha… Appreciate the candor.