On 3.09.2018 10:46, Alf P. Steinbach wrote:
> On 02.09.2018 23:55, Paavo Helde wrote:
>> [snip] Well, we can avoid writing std::, but why should we? Losing a
>> lot of clarity for ... what? Saving 5 keystrokes?
>
> No, it's about reducing visual clutter and verbosity. Reducing that
> improves local readability. And improved readability improves global
> clarity, the ability to understand the main things at-a-glance.
>
> Consider
>
> auto d = std::distance(a, b)
>
> The `std::` prefix tells you that you can look up the specification of
> this function, which will tell you what it computes and the exact type
> of `d`.
>
> That /possibility of later clarity/ might, to some, associate with
> direct clarity, compared to
>
> auto d = distance(a, b)
>
> ... which involves a possibly user-defined function that you possibly
> can't look up, e.g. possibly you don't even have the source code.
Yes, that's the point. I greatly prefer std::distance(), especially in
case of short lines and single usage like in your example. Especially if
it's in template code and some other 'distance' could be involved,
depending on the types.
>
> But there are just two main cases:
>
> * You are unclear on what `distance` does or produces.
> For clarity you will have to look up the function spec. In the case
> where `distance` is the standard library's function neither style
> helps you do that more easily. E.g. in Visual Studio, place the text
> cursor on `distance` and hit F1, that's it, regardless of which style.
So I need to perform a special operation in order to clarify something
which could have easily been written clearly in the first place.
And yes, if I'm looking at some foreign code or code written by myself
more than 3 months ago, I am always in doubt what it actually does. The
mere fact that I'm looking on it already means it is probably doing
something wrong. Anything which helps me to understand more clearly what
the code exactly does is greatly appreciated at that point.
And no, VS does not work nearly as reliably as you suggest (though it
has become better over years). And I don't always have the luxury to
work with an IDE, not to speak about one which can reliably look up symbols.
>
> * You are clear on what `distance` does and produces.
> Well.
>
> So with the in-your-face clarity of what each individual statement
> means, out of the picture, it boils down to: do the namespace prefixes
> that introduce more text to read and visually distracting `::` symbols
> all over, help readability?
>
> For me the `::` symbols and namespace names just reduce readability,
> greatly, and thereby reduce global clarity.
>
> Some others, maybe that includes you, maintain that for them they do
> help readability. I tend to not believe that claim but I don't entirely
> dismiss it, because it /can/ conceivably be like a suitable amount of
> the right kind of background music can help one focus on a task. I guess
> the mechanism is by keeping the otherwise too active parts of the mind
> occupied with the music, maybe.
Your beliefs do not change the reality ;-)
Anyway, I suspect that using or not using the std:: prefix usage has
mostly to do with habits. If I see std::max() and std::uint32_t all the
time in the code I get used to them and would feel lost without std::.
It looks like for you it is the opposite.
> So it seems possible that to some degree it's a subjective thing, but I
> would be very surprised if Mother Nature has evolved people so that a
> majority are helped in their thought processes by having `::` and
> redundant namespace names peppered all over the text, as background.
There is also the issue of namespace length. "std::" is short enough to
write out, some other namespaces not so, especially when used often.
There is also the issue of the codebase size and homogeneity. For
example I made a quick search of 'distance' in our codebase and
immediately found a 'double distance(double a, double b);' in a
third-party header.