Ruby Namespaces and source file size.

For Java programmer it will look at best a bad practice to include more than one class or module in a single source file.
Personally I think keeping code and source file at 1:1 ratio is much cleaner approach and is easier to manage for the following reasons:

  • You don’t have to guess which classes or modules are included in particular .rb file. The file name should tell what it class/module includes.
  • It is difficult to read a source file where it contains more than on class or module, unless the classes or module are small enough you soon will get confused which methods belong to which class or module.
  • We don’t want source files to be longer than lets say 1000 lines.
  • When used in source control repositories like CVS it will be a nightmare to have multiple developers work on the same physical file.
    This thought is problem as long as particular ruby file and included classes and modules are owned by one developer.

Ruby Namespace approach is another thing I don’t really like. To have classes/modules with the same name not to clash with each other during program load we need to declare them in different parent module, which means I have to include all classes/modules in one big file if I want them to have same Namespace.

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>