[Prev][Next][Index][Thread]

Re: multi-level namespaces?



On Tuesday, March 20, 2001, at 09:30 AM, Bruce Hoult wrote:

> I'm wondering if anyone can explain the reasons for the two-level  
> library/module affair in Dylan. 

Because it sucks less than multi level namespaces. :-)

Seriously, with re-exporting and renaming, you don't need more than two levels. More would be confusing without added advantages.

Let's look at Java and C++.

Java has two problems. The first is that:

import org.robmyers;

doesn't:

import org.robmyers.klin;

This confuses the hell out of newbies who assume the Java file structure system for classes in packages means the package include system will work like a filesystem. It doesn't. Those dots are just syntactic sugar for the programmer (although not for the compiler and linker), which brings us to the second problem.

The second problem is that Java has a flat namespace system anyway:

package com.greif.gabor.codewarrior;
package test;
package igloo.penguin.pingu;

are all the same "depth" of namespace. You can't reach around in a namespace-graph, you just have to fully qualify things, eg:

java.util.Date;
my.package.also.has.a.Date;

As Gabor says, mock-nested namespace names like Java has can be done in Dylan:

define library com/mine/assert
define library top-middle-bottom

Now, C++'s namespaces are different:

namespace klin
{
	namespace blim
	{
		class mau
		{
			enum stymie
			{
				aye, bee, see;
			}
		}
	}

	class wibble
	{
		typedef foom ::klin::blim::mau::stymie;
	}
}

Nested namespaces considered harmful. Like so much of C++, they are real real-man-programmer nonsense that introduces more opportunities for confusion and bugs than productivity. Also, the code I have to maintain breaks as they implement the standard. :-)

Having worked with Java for 4 years and C++ for the last 2 (after a break...), I prefer Dylan's 2-level re-exportable namespaces more all the time.

- Rob.

--
Rob Myers - http://www.robmyers.org/dylan
"The idea behind Dylan-to offer a range of dynamism appropriate to each piece of an application-feels right, and after using Dylan you will become frustrated with C++ and Java." - Software Development Magazine.