From: ptkwt@...1.aracnet.com (Phil Tomson) Date: 2001-12-05T10:23:54+09:00 Subject: [ruby-talk:27503] Re: Package Naming In article , Dave Thomas wrote: > >Right now, the naming of packages is something of a free-for-all: >people add their packages where they feel appropriate in the Ruby >library namespace. > >To a point, this is convenient for users. If I write a markup package, >users can do something like: > > require 'markup' > > m = Markup.new(..) > >However, as the library grows, I'm wondering if this simplicity could >lead to problems as we get name clashes and general confusion: does >the Trace module show program execution or outline graphic elements? > >The Perl solution is to have a module hierarchy. My markup program >might be in text/markup/simple.rb, and users would do something like > > require 'text/markup/simple' > > m = Text::Markup::Simple.new(...) > >or > > require 'text/markup/simple' > > include Text::Markup > > m = Simple.new(...) > > >However, this solution has its own drawbacks. As a user, all these >long strings of names it pretty daunting. As a module writer, it's a >pain to refactor, and moving things around ends up affecting a lot of >source code. Also, until Matz gets > > module Text::Markup > >implemented, you end up with a fair amount of additional indentation >in deeply nested files When will this be implemented? (is it a 1.8 feature or later?) I think we need this pretty soon.... > > module Text > module Markup > module OutputFormatter > > class ToHtml .... > > Yeah, that's bad. >So, what do folks think? Should we start implementing module >hierarchies, or is there a better way. Should RAA.succ enforce all >this? > I think module hierarchies are probably the way to go. Yes they have their drawbacks, but I don't see a better way to keep us from running over each other's namespaces. I've implemented a hierarchy in my Win32 extensions, and perhaps this is a good place to bring up something related to that... Since my Win32 module is a C extension and it will have many different classes within the Win32 module (but not a deep hierarchy, thankfully) I'm going to end up with lots of definitions in the Init_Win32() fonction of my C extension (RubyWin32.c). This function will get to be huge as more classes are added to the Win32 module hierarchy. Are there any ways of getting around this? I'm actually thinking of using my Ruby Template system as a sort of C pre processor that understands Ruby - RubyWin32.c would be generated from RubyWin32.template by looking in each subdirectory for code to include in the void Init_Win32() function defined in RubyWin32.template, but maybe I'm overlooking something easier... Phil