From: Robert Klemme Date: 2010-08-31T15:30:07+09:00 Subject: Re: Namespaces too looooooong On 08/31/2010 06:22 AM, Iain Barnett wrote: > > On 31 Aug 2010, at 03:29, Christopher Dicely wrote: > >>> Going back in time would be cool if it was in a time machine, but >>> throwing out the good things learned over the years about things >>> in computing seems the wrong way to do it. >> >> Is using deeply nested modules in such a way that a consumer of >> the module would be expected to reach deeply into the nesting >> structure a "good thing" though? It seems to me that deeply nested >> modules work best where the deeper layers are used by the higher >> layers, not by a external consumers. > > I completely agree. But, if you can find me a good article on how to > use nested modules as namespaces in a library, and how to refer to > different parts of the module from within and without, including > writing tests for it and how rake will interact with the changes, and > includes all the different ways it will affect `require`, while > avoiding many more articles that complain about libraries polluting > the global namespace and stomping all over each other then I'll also > agree not to look on comments like "use them less" as an > encouragement to be disorganised and more as an invitation to use a > facade :) Well, there is always one thing that you can do to avoid too much nesting: module A module B class X end end -> module A end module A::B end class A::B::X end There are however subtle namespacing implications so I generally avoid this. :-) The access problem for tests is usually solved by placing tests in the same namespace as classes under test. Then you can apply the same relative access path as for the code itself. > Because I tried, and there's bugger all out there. It's no wonder > there's been a problem with clashing because it appears that those > who know how to avoid it haven't bothered to tell anyone else. That's > not the best way to encourage best practice, IMO. Well, you should also consider that people might not have run into the issue you have run into in the first place. So there was nothing bad that they needed to learn how to avoid. :-) Also, the general practice in Ruby seems to be to not nest too much (Ruby programmers are quite lazy as far as I can see). I can't remember having seen more than three modules nested as namespaces - it's certainly quite rare. Also, we tend to use short names... Maybe you do not need to throw out too many things but adjust what you learned over the years to Ruby style. It is generally easier to go with the flow than try to literally translate concepts from other programming environments to the new language. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/