Best Practices: Classes inside of a Module

You can create classes inside of a module which gives you your own kind of namespace amongst other things

Anyone have any tips for best practices on this? When do you put classes inside of a module? What do you use them for?

I don’t do this only because, if you do, you can’t make the module external to the project. Otherwise, for examples of where this is done, see the MacOSLib project, among others. One advantage is that the Module gives you a place to put common properties, constants, and methods that all the embedded classes can use.

One advantage of putting a class into a module is that protected and private methods, properties, etc. of the module can be accessed by the class.

I went through a phase of doing just this, but like Kem says, it becomes very complicated once you want to have the objects external, not to mention I ran into issues with code editor ‘suggestions’ and enums in classes that are in modules.

Usually when I distribute code as free open source to other users. It just makes things easier for users wehn everything is wrapped into one single file that can easily be imported.

The feedback request that gets the #1 position in my top cases (and are awarded the most points)… <>… External Module Support.

It will be a huge time saver if modules that contains classes can be made external.

This one is pretty big for us. I’ve added it to my top cases. Currently #44.

One thing I don’t like is you can’t encrypt an entire module. So you can put private methods inside a module but theres no way to guarantee the class doesn’t leave the module.

I’d love to support external modules with contents.
I’ve actually worked on it several times over the past 5+ years with other engineers starting with Aaron way back when.
WIthout spending a week detailing why its so danged hard to do I can just say that it’s a real bugbear to solve.


More thoughts?

I’ve added it to my top cases too. Just today spent a lot of time tried to share a module among few projects.

The only way I found - is to use symlinks.

if you use svn check into svn sub projects which you can use to do this