Hello
german diago wrote:
> Hello. I've been checking the proposal to add modules to C++ and it's
> great! I know there's quite a few time left for that proposal to be
> added to the language. But anyway, I have some suggestions for modules
> in C++. I know it's not a finished proposal, so maybe what I say here
> is quite obvious but has not been included in the paper.
>
> The paper is here:
>
> http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2316.pdf
>
> 2.- When using an im****t directive, I think that it would be useful
> that the im****t directive had an implicit using namespace, because
> it's soooo verbose to use today's c++ with namespaces, that people (at
> least this is true for me and some friends I know) don't nest more
> than two namespace just because of its verbosity.
I do not agree. If people need "using namepsace" they can do it in the
current proposal but alot of people (such as myself) do not need it and
your sugestion would force it for these people. I wouldn't use "using
namespace" for ANY big namespace with alot of common names (one good
example is "std" where it makes sense to write "std::list" as oposed to
just "list" since in a big project you have several kinds of lists from
various places).
BTW, I am one of those having alot of nested namespaces (max 3 levels, but
I
do have alot of 2 levels namespaces) and I don't mind at all the verbosity
especially since you can opt it out with "using namespace", "using" or
namespace aliases to make local short aliases for longer namespaces (such
as I do for "boost::filesystem" which usually gets a "bfs" alias almost
everywhere in non-header code).
>
> 3.-
> //Im****ting module std (package std in my wording)
> im****t std;
>
> //Now I can use vector<int> or list<int> without std::; because there
> is an implicit using namespace std
> //with the im****t statement.
Which is wrong because IMO "std" is one of the clear examples where "using
namespace" would result in bad code. Generally I can see the utility
of "using namespace" as this:
1. if the namespace is very big named (including the nesting and such),
but
here a better option is a local shorter namespace alias
2. if the namespace has not many "generic" names (std is the opposite,
having alot of too general names such as "list", "vector", "pair" that
have
high chance of name clashes)
3. if the "using namespace" is done in a very local context, such as a
function body or a "cpp" file (but mandating "im****t" to do "using
namespace" breaks this completely since people would want to use "im****t"
even in headers I supose which will bring all those general names I fear
about in any code that indirectly includes this header, which leads to
very
risky situations since includes may be added by someone else not realising
they will bring the whole "std" names in the current scope)
4. if the names of the namespace that will be brought in current context
are
clearly known (and "std" again is the opposite since doing "using
namespace
std" may bring alot more than what you know as being the "public" std
names, it may bring implementation specific names, thus a recipe for name
clashes)
Doing "using namespace std" automatically with "im****t std" beats all the
purposes above I believe.
>
> //vector is a module partition (module in my wording), so namespaces
> in std::vector module should be ex****ted.
> im****t std::vector;
>
> This makes code much less verbose. In the case of ambiguities, you can
> still fully qualify a name and makes
> coding less verbose.
Are you saying that you have "using namespace std" in your commonly
included
headers? And you don't have name random clashes because someone else in
his
module decides to include something that indirectly will be included by
your code and leading to the name clash?
That is the problem with "using namespace", the more you use it the more
the
risk of having name clash by unrelated changes, thus your code is
not "stable" enough.
--
Dizzy
[ See http://www.gotw.ca/resources/clcm.htm
for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


|