4 ms·
I thought the complaint was about the logic duplication, not the extra keystrokes. If you want type inference you already have auto. If you want to minimize you
by mehrdadn 6y ago
I thought the complaint was about the logic duplication, not the extra keystrokes. If you want type inference you already have auto. If you want to minimize your keystrokes, you're using the wrong language to begin with, whether there's type inference or not. C++ is designed for writing software robustly, not quickly. (<-- This is not a trivial or obvious statement btw. It took me several years to grasp this. And I viewed C++ from an entirely different perspective when it finally sunk in for me that I would appreciate C++ much more if I decided to make minimizing keystrokes a non-goal.)
- secondcoming 6y ago> If you want type inference you already have auto or auto&&. Did you really intend to make a copy?
- mehrdadn 6y agoYou probably did intend it to be a copy if you're binding it to a variable and need it to be non-const (like in the example)!
- secondcoming 6y agoAh, but you knew that because that's how the code was written! If it was instead String foo = "bar"; auto baz = foo; you don't know for sure. But the code compiles so it obviously ok!
- mehrdadn 6y agoNo, I'm saying even in that case you know it was intended to be a copy. If you wanted that to be a reference then you'd either (a) just do the obvious thing which is to just use the original variable name instead of creating a new variable out of the blue for no reason, (b) leave a comment explaining why you're not doing the aforementioned obvious thing, or (c) use a self-explanatory variable name to provide the explanation instead of a comment.