4 ms·
Ugh, that is even more ill-advised than using auto without good reason in C++.
by ahartmetz 7y ago
Ugh, that is even more ill-advised than using auto without good reason in C++.
- MaxBarraclough 7y agoIn the interests of perpetuating this endless flamewar, here's Herb Sutter saying C++ programmers should use auto 'by default'. (I see my snarky comment there got no reply.) https://softwareengineering.stackexchange.com/a/180616/ https://softwareengineering.stackexchange.com/a/180616/
- jfkebwjsbx 7y agoHerb Sutter is biased. He works on C++ language lawyering, he works on new features, he works in the STL, etc. People like him tend to be biased about using auto because they write mostly libraries and generic ones at that (data structures, for instance). In most code out there you actively avoid templates if possible, so that code is concrete, compiles faster and is easier to debug.
- dirtydroog 7y agoBingo! Writing a template library is totally different to writing an application.
- Koshkin 7y agoWell, there's two ways to write an application, analogous to two styles in mathematics as described by A. Grothendieck. http://www.landsburg.com/grothendieck/mclarty1.pdf http://www.landsburg.com/grothendieck/mclarty1.pdf
- Koshkin 7y agoIn the context of C++, the use of auto allows to avoid unintended type conversions during initialization.
- GoblinSlayer 7y agoAnother reason for C/C++ is that they are very permissive with implicit lossy conversions. If you specified explicit type, chances are the compiler helpfully made a lossy conversion for you.
- jfkebwjsbx 7y agoIf you use only explicit constructors and ban cast operators except for the most basic of types, then you have a sane language and explicitness in your code.
- MaxBarraclough 7y agoSounds sensible. Google seems to agree with you. https://google.github.io/styleguide/cppguide.html#Implicit_Conversions https://google.github.io/styleguide/cppguide.html#Implicit_C... LLVM's coding standard though doesn't seem to have anything to say about implicit conversions: https://llvm.org/docs/CodingStandards.html https://llvm.org/docs/CodingStandards.html
- GoblinSlayer 7y agoIt's sane on C++ scale, but on absolute scale that sanity is still wanting, Sutter mentions this.
- MaxBarraclough 7y agoSutter made that point under Maintainability and robustness. Like Sutter's answer, this point doesn't answer the complaint. People on the anti-auto side say it seriously harms readability, as locals' types are no longer clear at a glance. They aren't asking for a list of reasons why some people favour auto, they're asking for an answer to their readability problem. Perhaps IDEs could infer types and display them as a superscript. That would keep just about everyone happy. (Perhaps not Vim users.)
- skocznymroczny 7y agoIn IDE-friendly languages like Kotlin, you can enable showing of inferred types, e.g. https://i.stack.imgur.com/tiqjc.png https://i.stack.imgur.com/tiqjc.png