[Please do not mail me a copy of your followup]
Jorgen Grahn <
grahn...@snipabacken.se> spake the secret code
<slrnm6khsa.1...@frailea.sa.invalid> thusly:
>On Mon, 2014-11-17, Richard wrote:
>> [Please do not mail me a copy of your followup]
>>
>> Robert Hutchings <
rm.hut...@gmail.com> spake the secret code
>> <m48etn$1cn$
1...@dont-email.me> thusly:
>>
>>>On 11/15/2014 2:39 PM, Jorgen Grahn wrote:
>>>> On Sat, 2014-11-15, Robert Hutchings wrote:
>>>>> As I read the C++ 11 and C++ 14 changes, I was wondering if there are
>>>>> any tools one could use to update older code to incorporate the 2011 and
>>>>> 2014 updates? Or is just a manual "do it yourself" thing?
>>>>
>>>> What would be the point of automating it? You don't learn anything
>>>> from that.
>>
>> Any refactoring you can perform automatically is 100x more useful than
>> any refactoring you must perform manually. The larger the code base,
>> the higher the multiplier on the usefulness.
>>
>> Doing it once or twice is all it takes to learn something. Doing it
>> hundreds or thousands of times across your code base is just drudgery.
>
>You don't answer my question, though: what is the point?
One might as well ask:
Since C++ can be transformed into C, what is the point?
The point is that using C++ allows us to get the job done at a higher
level of abstraction than C, without losing the efficiencies of C. We
get the compiler to do more work for us so that we can work in a
manner that is expressive and intention revealing without having to
shove a thousand implementation details up into your face in every
function.
If there was no point to these features in C++11, they wouldn't have
been introduced.
As far as the transformations performed by clang-modernize:
- use of range-based for loops makes loops easier to read;
intent is clearly revealed without excessive syntax
- use of nullptr makes pointer use more explicit;
intent is clearly revealed without ambiguous syntax
- use of auto removes unnecessary syntactic noise;
using nested iterator typedefs to declare iterators just makes for
syntactic noise that gets in the way of clearly reading the intent
- use of override makes explicit when methods are being overridden and
more clearly reveals intent; this can result in bugs being found if
the intention was to override a method in the base but the method
name was misspelled or the signature didn't completely match
- use pass by value; the intention is more clearly revealed. We don't
need to chase through implementation details to discover that the
only reason references were used was to achieve some sort of hand
optimization that the compiler can do for us automatically with move
semantics, copy elision and return value optimization.
- replace auto_ptr with unique_ptr; replace error-prone semantics of
auto_ptr with well defined semantics of unique_ptr. This one may be
a toss up depending on your team and your code base.
>You now have
>converted your code to a dialect of C++ which few people understand,
Few people? LOL. C++11 has been around for about 3 years and none of
the above transformations, with the possible exception of the auto_ptr
-> unique_ptr change, are going to throw any decent programmer into a
tizzy. Every time I've shown existing C++ programmers these new
features through examples they always got it within a few seconds.
SECONDS.
These features aren't rocket science and don't take very long to learn.
We're not talking esoteric guru level template metaprogramming here.
It's syntactic sugar for the most part.