what's so difficult about namespace?
Dimiter "malkia" Stanev
malkia at mac.com
Thu Nov 27 03:28:15 CET 2008
I myself am proponent of namespace-lessness... That was until I
discovered CLOS and the multi-methods...
For any other language I would pick Apple's approach approach to
Objective C, and the frameworks that they've put (libraries) - e.g. use
couple of letters to prefix your class/functions - like NSObject,
ABAdressBok, UIButton. For these languages, where only single-dispatch
is available, there is no need to prefix their methods, as they are
always send to one object, and this object itself becomes a "package" -
basically it would grok certain "words", "messages", "id-s" whatever you
But let's go back to CLOS:
Take for example the Lispworks CAPI gui library. To display a component
you normally do:
If you haven't added the CAPI library to the (:use) list then you do:
But let's say you have another library used in your application, that
has the same multi-method "display". For example a PDF library might
To call it, you would again do:
And if you haven't added the PDF library to the use list:
In the case where both libraries (:use "CAPI" "PDF") are used, there
would most likely be a problem, but at least you can solve it by
prefixing it with capi: and pdf:, but this would still keep short-naming
in the rest of the modules where that's not needed. The more decoupled
the system, the less you would run into such problems, and most of the
coupling is in the actual application code (not libraries) where you
And overall it would be better than naming your methods like this:
Yes this would be safe everywhere, and granted such naming works well
for functions, classes, global variables, etc - but really for METHODS,
being a MESSAGE it makes it unattractive.
Other than that, packages (namespaces) in Common-Lisp are also used for
special cases: The KEYWORD package, The SETF one, and COMMON-LISP would
always be the bible :)
Dimiter "malkia" Stanev.
Xah Lee wrote:
> compared the 2 languages.
> 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. PHP didn't have namespace for the past decade till
> didn't have namespace as he mentioned in his blog. Elisp doesn't have
> name space and it is a well known major issue.
> 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.
> 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. 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?
> Could any compiler expert give some explanation?
> ∑ http://xahlee.org/
More information about the Python-list