Juliean said:
It doesn't add anything of value
From whose perspective? The original author who already has context for the code or the people who maintain it starting as blank slates? You’re just saying that type explicitness is of little value to you because you aren’t going to encounter situations where you have to infer the type or to learn about the type by hitting F12 on it.
For people who are new to your code, it is very valuable to have the types spelled out for you; it is a lot less time spent inferring things and spelling out the type makes the learning process easier since you can just click it and hit F12 to go to the class definition and freely continue your learning experience. Obstructions to the learning experience add up and it’s unfair to discount the value of explicit types just because you won’t have to go through that learning experience. If I am trying to fix a bug in an algorithm I didn’t create, it is extremely helpful to easily see at a glance the signs and number of bits in each type so that I can more easily recognize potential discrepancies and spend more time focusing on the algorithm rather than maintaining a mental database of information that should have already been clearly spelled out.
It is incorrect to “never use auto
,” but it’s probably more incorrect to “freely use auto
.” auto
should be used sparingly and only when it actually improves readability of the code, which is mostly when it can be used to replace long type names such as STL iterators or when a variable might change types between different builds and would require some #ifdef
clutter otherwise. These are tangible decreases in clutter that justify the obfuscation introduced by auto
. “Entity
” or “float
” or “uint32_t
” aren’t enough clutter to justify the obfuscation.
L. Spiro