2 ms·
auto can be a great aid to readable and maintainable code. It can also be used to obfuscate when not used in moderation. for(const auto& elem : container
by rleigh 11y ago
auto can be a great aid to readable and maintainable code. It can also be used to obfuscate when not used in moderation.
for(const auto& elem : container)
is vastly more readable than
for(my_long_type<specialised_type>::const_iterator iter = container.begin(); iter != container.end(); ++iter)
I recently had to rewrite some C++11 code to C++98 to fit into a project. Using nothing but auto and range-based for loops, it nearly doubled in size by switching back to the older more verbose syntax. So long as you don't go to the other extreme, these have much value.
- jheriko 11y agoits also a death trap in winrt when combined with templates in the way they do. debugging that typoing a callback signature results in nothing happening in asynchronous code controlled by the ppl task library is a massive pain for even an experienced programmer. auto is nice in principle, but it is introduced in such a powerful and dangerous environment that there are subtle gotchas in real world use cases. including targetting a major platform by using its system libraries. programming is about thinking, not typing and programmer convenience. i don't enjoy auto for that reason either... if it were to save me time it would be little. i find using the stl algorithms and avoiding the nasty stl iterator pattern like the plague means the problem you describe just doesn't exist for me as a day-to-day case.