what's so difficult about namespace?

MRAB google at mrabarnett.plus.com
Wed Nov 26 16:45:03 EST 2008


Kaz Kylheku wrote:
> On 2008-11-26, Xah Lee <xahlee at gmail.com> wrote:
>> comp.lang.lisp,comp.lang.functional,comp.lang.perl.misc,comp.lang.python,comp.lang.java.programmer
>>
>> 2008-11-25
>>
>> Recently, Steve Yegge implemented Javascript in Emacs lisp, and
>> compared the 2 languages.
>>
>> http://steve-yegge.blogspot.com/
>> http://code.google.com/p/ejacs/
>>
>> One of his point is about emacs lisp's lack of namespace.
>>
>> Btw, there's a question i have about namespace that always puzzled me.
>>
>> 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.
> 
> Scheme hasn't officially supported breaking a program into multiple files until
> R6RS. If the language is defined in terms of one translation unit, it doesn't
> make sense to have a namespace feature.
> 
>> 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.
> 
> Javascript programs are scanned at the character level by the browser as part
> of loading a page.  So there are severe practical limitations on how large
> Javascript programs can be.
> 
> Namespaces are useful only in very large programs.
> 
>> Elisp doesn't have
>> name space and it is a well known major issue.
> 
> C doesn't have namespaces, and yet you have projects like the Linux kernel
> which get by without this.
> 
> Given that the Linux kernel can do without namespaces, it's easy to see how
> Javascript and Elisp can survive without it.
> 
>> 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. The
>> _essence_ of namespace is that a char is choosen as a separator, and
>> the compiler just use this char to split/connect identifiers.
> 
> The essence of a true namespace or package system or whatever is that you can
> establish situations in which you use the unqualified names.
> 
> You can emulate namespaces by adding prefixes to identifiers, which is
> how people get by in C.
> 
> In C, you can even get the functionality of short names using the preprocessor.
> 
> I have done this before (but only once). In a widely-used public header file, I
> prefixed all of the names of struct members (because struct members are not
> immune to clashes: they clash with preprocessor symbols!)
> 
>   struct foo {
>     int foo_category;
>     time_t foo_timestamp;
>     /* ... */
>   }
> 
> Inside the implementation module, I made macros for myself:
> 
>   #define category foo_category
>   #define timestamp foo_timestamp
> 
> In this way, I didn't have to edit any of the code in order to move the struct
> members into the namespace. Expressions like ``pf->category'' continued to work
> as before.
> 
>> Although i have close to zero knowledge about compiler or parser, but
>> from a math point of view and my own 18 years of programing
>> experience, i cannot fathom what could possibly be difficult of
>> introducing or implementing a namespace mechanism into a language.
> 
> The same things that make it difficult to add anything to a language, namely
> the stupid way in which languages are designed to get in the way of extension.
> 
> What would it take to add namespaces to C, for instance?
> 
> If you have any proposal for a new C feature, the ISO C people encourage you to
> develop a proof-of-concept, which means: hack it into an existing
> implementation to demonstrate that it's feasible.
> 
> If you need new syntax, hacking it into an implementation means hacking it into
> the parser. Everyone who wants to experiment with your feature needs to get
> your compiler patches (for GCC for instance) and rebuild the compiler.
> 
> The process is painful enough that it's only worth doing if it solves something
> that is perceived as being a critical issue.
> 
>> 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?
> 
> I recently read about a very useful theory which explains why technologies
> succeed or fail. 
> 
> See: http://arcfn.com/2008/07/why-your-favorite-programming-language-is-unpopular.html
> 
[snip]
The correct URL is 
http://arcfn.com/2008/07/why-your-favorite-language-is-unpopular.html



More information about the Python-list mailing list