Re: C++ Frequently Questioned Answers
on Mon Nov 05 2007, Walter Bright <walter-AT-digitalmars-nospamm.com> wrote:
David Abrahams wrote:
Yes. Exception specifications are a technical success
In what sense?
They are easily implementable and work according to the Standard (i.e. a
technical success). They aren't useful, though (i.e. a semantic failure).
but a semantic failure, and export is both a technical and semantic
failure.
I guess that's where we differ -- I don't see namespaces as an attempt
at modules, failed or otherwise. In fact, I have a hard time seeing
enough similarity to figure out how they could be viewed as an attempt
at modules, period. A namespace defines a scope for names -- nothing
more and nothing less.
In aiming so low, namespaces aren't much of a solution to
anything. You could just as well use prefix_name rather than
prefix::name.
Just like you could also write this->member when "member" would do.
At least that practice serves some practical purpose in C++.
We use prefixes to avoid macro name clashes, but we don't like it.
Prefixes suck. Namespaces allow expressive code without name clashes,
because local names and explicitly-imported names from other modules
can be used without qualification. As I've implied elsewhere, ADL is
the only thing that messes that up.
What also messes it up (and motivated the development of overload sets
in D) is when you import namespaces so you can skip the explicit
qualification, then later import another namespace
You mean via using-directive?
with conflicting names, and now your source code is all messed up.
Messed up how? Naturally you can get ambiguities if you bring
multiple names into a scope without qualification. That's why you use
qualification.
As far as I know, there's no silver bullet for that, which is why you
generally shouldn't make whole modules (in languages with modules) or
namespaces available for use without qualification. Anybody
maintaining these other modules might decide to add a new name that
you're already using for something, with inevitable compilation errors
if you're lucky; semantic changes if not.
D somehow magically resolves all the ambiguities in just the way the
programmer wants, every time?
(ADL is C++'s partial answer to that problem.)
I guess that's one way to look at it. I think of ADL as being for
finding names *without* importing them.
--
Dave Abrahams
Boost Consulting
http://www.boost-consulting.com
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]