"Jorgen Grahn" wrote:
> On Sat, 2018-04-28, Jouko Koski wrote:
>> Having to repeat the namespace name everywhere does not improve
>> readability.
>> It adds noise, induces boilerplate typing and it looks ugly, albeit it
>> does
>> make the identifiers more explicit.
>
> Then I'm with Juha (I think it was): I think accepting the namespaces
> is the best overall solution. So I refer to things as "std::foo" and
> to "bar::foo" in my code (if that code isn't also in bar).
Making a virtue of necessity! Yes, it is more explicit, but it cripples
readability.
> It no longer looks ugly to me, and it typically doesn't mean a lot of
> repetition (especially nowadays with C++11 auto).
Well, it is ugly and there is still a lot of repetition.
>> struct thing {
>> void func(string s);
>> };
> If we focus on the interface: to me, if that had appeared in a header
> file, I'd worry about what 'string' meant, since it didn't say
> 'std::string'.
I trust you not being that inept in real life! People using some other
languages that have packages or modules mechanism seem to do quite ok
with this issue.
If there were "string", "buffer" or "socket" in some declaration and
there is "std" or "boost::asio" in the same cognitive scope, one should
be able to assume that string, buffer or socket cannot be just anything.
They are supposed to be coming from std or boost::asio without the need
of repeating the full namespace path on every single occurrence.
When it comes to this particular toy example, string is probably the
most used type in the standard library. I would expect that if there
were any other kind of string in the same context simultaneously, it
is that string that should be addressed as the other::string without
having to drag the std:: prefix to everywhere else. Having "using
namespace std;" in the global scope might not be that bad idea after
all but that is another story.
> I can appreciate an abbreviation like this in an interface:
>
> using ResolverMap = std::map<std::string, std::list<IpAddress>>;
>
> but then I'm getting something more than removal of the std prefix.
Yes. When it comes to code readability, this declaration is over 60
characters long. It is a bit challenging to try to limit the max line
length to 80 when this kind of stuff tends to be the norm. About 10 %
of it is colons and the "std::" is repeated three times. That resembles
noise.
--
Jouko