Brian Schröder
1/19/2005 2:18:00 PM
On Wed, 19 Jan 2005 17:51:02 +0900
"Johan Nilsson" <johan.nilsson@---.esrange.ssc.se> wrote:
> Hi,
>
> having grokked Ruby for a while now I wonder whether there are any specific
> recommendations regarding file/directory naming. IF so, where's the place to
> look?
>
> I've been using C++ for quite a while, and what made sense to me was to aim
> for one class/file and name the file after the class - e.g. MyClass =>
> MyClass.h, MyClass.cpp.
>
> If the class were defined inside a namespace (roughly comparable to modules
> in this specific instance), I'd ususally create a subdirectory reflecting
> that, e.g.:
>
> --- MyNs/MyClass.h --
> ....
> namespace MyNs {
>
> class MyClass {};
>
> } // namespace MyNs
> ....
> ---------------------
>
> To refer to this header from other files I use e.g. "#include
> <MyNs/MyClass.h>". This seems pretty consistent with e.g. "require
> 'test/unit'".
>
> But - back again to my real question (and now a bit more specific): why all
> this lower-case only in the files/directorys(that map to module names)
> within Ruby? As an example: compare Test::Unit::TestCase to
> test/unit/testcase.rb - any specific reason for this?
>
>
> Regards // Johan
>
>
>
I like grouping functionality into one file. There is no reason like in java to have only one class per file. And I often create really small classes for simple tasks, so it would be tedious to have that many files.
On the other hand one module may stretch along various files, if those add functionality to the module. In some cases I even have multiple files per class, such that I can choose the subset of functionality I need for the class.
The only advantage of one class per file is easier browsing if you have a bad editor, but this can be overcome easily with using e.g. emacs or even a ruby ide like arachno ruby (Never tried it, but there are lots of people here on the list who seem to like it).
just my 0.02___
Brian