DEV Community

Discussion on: Let's learn some modern C++!

pgradot profile image
Pierre Gradot • Edited

Point 1 : you can remember to initialize values without auto, but you can't forget to initialize them with it. That's quite not the same.

OK, I have to admit: I almost never use auto v = short{3} 😆

Furthermore, tools like clang-tidy warn me when a variable isn't initialized.

Point 2 : if your code is so long that you can't even remember what is grid and why you are trying to iterate over it, then not using auto seems quite a poor way to improve the overall function ;)

I used to think the same as you are doing now, I (sort of) forced myself to use auto at the beginning, and now I find code more readable in a case like this one. Also, I made a parallel between auto in C++ and Python, where (somehow) everything is auto. It's just a different way of thinking from traditional C++ or C.