<kentda / stud.ntnu.no> wrote in message news:<Pine.LNX.4.33.0109211132490.8002-100000 / gaupe.stud.ntnu.no>...
> On 21 Sep 2001, Ryo Furue wrote:
> > This makes me think that Ruby really needs to hide its "standard
> > library" (File, Time, Socket, etc.  Is "Data" part of it?) into a
> > single namespace and to keep the default namespace as clean as
> > possible.  Currently it's too much "polluted" (no derogatory meaning
> > intended).  C++ did this in its international standard: it hides all
> > its standard library in the namespace "std".  If you don't know C++, I
> > illustrate the idea in pseudo-Ruby code:
> 
> I would hate to have to prepend every usage of the library classes with
> Std or something like that. Doing a
> 	require "Std"
> would degenerate into the loathed "using namespace std;" on global level
> in C++.

Right.  So I'd like to have a mechanism to "require" only those names
which I use; such as,

	using std::cerr; // import only cerr
	cerr << "hello\n";  // without "std"
	std::cout << "world\n"; // "std" needed.

I'd be happy to write something like this:

	require File from "Std" # import only File
	f = File.open(....) # without "Std"
	d = Std.Data.new    # "Std" needed.

> My personal views are:
> 
> - 1) The commonly used parts of the standard library should not move into
> a namespace. Some parts might benefit from being in specific namespaces.
> But putting Array, Hash etc in such a namespace will only increase tedium.

I agree.  Fixnum and such things are best in the default namespace.

> - 2) Every class, module etc that the standard library provides in the
> global namespace should be documented. Your problem should not have
> extended beyond looking up the standard library reference and finding a
> "Data" entry. Rather than seeing a documenting nightmare, I too wish for a
> lean global namespace.

In fact, I was a bit shocked to find such an undescriptive name as
"Data" in the global namespace.  In my view, "library" names should be
more descriptive.  If so, the probability of name collision would be
lower.  Of course, Array, Hash, etc. are exceptions; they are almost
part of the core language (the part which almost everybody uses), not
part of the "library".

> - 3) Application and extension writers should use namespaces. That goes
> for medium sized scripts also. The main entrypoint is all that ought to
> rear its head in the global namespace.

Agreed.

Cheers,
Ryo