Open full view…

On using 'auto' and 'var' // A Random Walk Through Geek-Space

Fri, 28 Jul 2017 16:16:36 GMT

Fri, 28 Jul 2017 16:16:36 GMT

That's a weird conclusion that people are afraid of "auto" because it's unfamiliar to them. The thing that "auto" does is goddamn simple, you don't have to be a brainiac to understand how type is deduced. It all depends on whether you spend more time reading or writing the code. If you spend more time reading the code, you don't like to jump to function/variable declarations too often. You want the current block of code to be as descriptive as it can be, instead of jumping and trying to figure out what every function within the scope returns. Stating the type directly in a code is not such a big deal, unless you lazy enough to type extra characters. You're right, both of your examples will require a person who reads the code to jump to figure out what the type of "name" variable is. Although in the first case one is enforced to check variable type, but in the second case it's a responsibility of the developer who wrote the code to provide highly readable and maintainable sources.