what's so difficult about namespace?

Joshua Cranmer Pidgeot18 at verizon.invalid
Wed Nov 26 08:45:38 EST 2008


Xah Lee wrote:
> In many languages, they don't have namespace and is often a well known
> sour point for the lang. For example, Scheme has this problem up till
> R6RS last year. PHP didn't have namespace for the past decade till
> about this year. Javascript, which i only have working expertise,
> didn't have namespace as he mentioned in his blog. Elisp doesn't have
> name space and it is a well known major issue.

Namespaces are useful for one reason: they allow you to have conflicts 
with names in some cases. In Java, there are two Lists: java.awt.List 
and java.util.List. Since a name must only be unique within a namespace, 
you can use shorter names without fear of conflict.

In languages without these namespaces, you end up with stuff like 
g_type_init, e_data_server_module_init, mysql_connect, etc., where the 
prefixes are used to emulate the unique nature of namespaces.

> Of languages that do have namespace that i have at least working
> expertise: Mathematica, Perl, Python, Java. Knowing these langs
> sufficiently well, i do not see anything special about namespace.

Most features aren't sufficiently appreciated until one has to do 
without it. The avoidance of collision that comes with namespaces has 
shown to be sufficiently useful that I doubt we'll ever see a future 
major language that doesn't have some sort of namespace feature.

 > The
> _essence_ of namespace is that a char is choosen as a separator, and
> the compiler just use this char to split/connect identifiers.

That's just composition of namespace names. It's not what namespaces is 
about.

> i cannot fathom what could possibly be difficult of
> introducing or implementing a namespace mechanism into a language.

Namespaces go to the very core of a language, name resolution. 
Retroactively adding such a feature is extremely difficult because there 
is a strong chance of accidentally breaking existing code.

 > I
> do not understand, why so many languages that lacks so much needed
> namespace for so long? If it is a social problem, i don't imagine they
> would last so long. It must be some technical issue?

It's technical: it would be difficult to retroactively implement such a 
feature.

-- 
Beware of bugs in the above code; I have only proved it correct, not 
tried it. -- Donald E. Knuth



More information about the Python-list mailing list