Subject: Re: [boost] usage of auto in tutorials
Date: 2019-03-19 15:36:40
> -----Original Message-----
> From: Boost <boost-bounces_at_[hidden]> On Behalf Of Stephan Menzel via Boost
My personal rule of thumb for tutorial and demos is similar to how
you handle abbreviations in written text:
First time you e.g. use a function, you explicitly show what the
function returns. Afterwards I use auto where it makes sense
(And yes, I know there are conflicting opinions about
"where it makes sense").
With respect to the specific examples:
- Trailing return types in function declarations:
If the style guide doesn't say something different, I only use
them for very long type names and when they are needed.
None of this applies here, so I don't see the benefit,
but also not any harm. I'd say it is personal/project preference.
- The auto inside the if:
The return type of the function is shown just two lines above.
Again, personal opinion, but I'd claim it even increases
readability, because it is less visual noise.
> But for some people this looks very unusual. For example, because they are
> not aware of this new syntax or they have not applied it and still write
> functions the old fashioned way.
As I wrote, I rarely use trailing return types and I'm generally
no advocate of using auto everywhere, but this "new" syntax has
been valid c++ for more than half a decade now. If a professional
c++ programmer is still unfamiliar with this, then maybe more
exposure to it is actually a good thing and if boost doesn't spread
the word who does?
Also, where does this end? Should tutorials stay away from
rang based for loops? Smart pointers? Templates? Namespaces?
C++ features all together?
I know I'm exaggerating a bit, but I think it is a valid question.
From the perspective of a c programmer, all those things are "new".
However, outcome is a c++14 library so using c++14 features "where
they are usefull" should not be avoided, but embraced.
Again, I'm not suggestion auto should be used everywhere, because it really
can decrease readability significantly, but imho example code (regardless of
the context) should reflect current best practice and not based on guesswork
about what language the users might be most familiar with.
Don't be afraid of change.
\ rant off
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk