|
![](/i/fill.gif) |
Darren New <dne### [at] san rr com> wrote:
> > People say "it would reduce readability/maintainability", "many experts
> > advocate the usage of 'using' statements". Could some rational arguments
> > explaining these claims be given?
> Interestingly enough, for the couple of years I hung around on the Ada
> newsgroups, this was one of the ongoing repeated flamefest topics. Some
> people thought it was always dangerous to use the Ada equivalent of
> importing a namespace, some people thought it was reasonable for namespaces
> equivalent to the sorts of things you find in std:: (like variable-length
> string managment, etc). Most people agreed it was OK if you limited the
> scope of the import to (for example) one routine at a time. Of course, in
> Ada you can nest procedures inside other procedures, so that was less of a
> hardship than it would be in C++.
> FWIW, I don't remember anyone on the Ada groups ever providing actual
> scientific evidence one way or the other either. And I'd think if there's
> any programming language where that sort of evidence would be around, it
> would likely be Ada.
"using namespace" statements might in some cases be justifiable if the
name of the namespace is very long and/or there are many nested namespaces
(which is sometimes the case). However, a common recommendation in these
cases is to use namespace aliases instead (which is possible in C++). It's
a bit like a typedef, but for namespaces. For example:
namespace bid = boost::io::detail;
After that you can use 'bid::' instead of 'boost::io::detail::' as the
prefix for names in that namespace.
However, this should only be considered as a convenience shortcut, similar
to using a typedef to shorten very long type definitions. Abusing it to the
extreme should be avoided.
Personally I have never understood the aversion many people have against
the 'std' namespace. It's very short, so it's not a question of it being
laborious to write. And as I have argued elsewhere, using the namespace
prefixes actually makes the code easier to read and understand, while
avoiding them can sometimes make the code more obfuscated, requiring more
work to understand what is it doing.
--
- Warp
Post a reply to this message
|
![](/i/fill.gif) |