3 ms·
Okay, if I replace auto, then you know that employee is of type "EmployeeRec". Happy? Of course not. That still tells you basically nothing. Surely it does not
by RogerL 11y ago
Okay, if I replace auto, then you know that employee is of type "EmployeeRec".
Happy? Of course not. That still tells you basically nothing. Surely it does not tell you what the store function does (I argue 'storeXXX' is generally a bad name, the point is to use a good name for functions, I just threw boilerplate there).
Comments plus good names will tell you what is going on. Replacing 'auto' with 'std::vector<EmployeeRec>' for the most part, doesn't.
I'm not being dogmatic. If having the type there is important, then of course use the type, not auto. But it seems that everyone who writes a rant about auto shows us code with no comments, and terrible, meaningless variable and function names. Get that part right, and then, if you are still puzzled, and the code isn't meant to be generic, sure, put the type in. Why not?
Somehow I manage to write and read tons of dynamic code that has no types whatsoever. I agree, sometimes I would like a type there, and that is a perfect time to not use auto. But in general, we are trying to write code at a higher level. I mostly don't want to write, or think about
for (std::my_vector<some_long_type> i = blah.begin();
Sometimes I do, and in those cases I'll write it that way.
- slavik81 11y agoYou mean for (typename std::my_vector<some_long_type>::const_iterator i = blah.begin();