String foo = "bar"; String baz = foo;
The `String`s can be completely avoided in languages with type inference because it's obvious that a string literal is a string.
String foo = "bar"; String baz = foo;
The `String`s can be completely avoided in languages with type inference because it's obvious that a string literal is a string.
or auto&&. Did you really intend to make a copy?
If it was instead
String foo = "bar";
auto baz = foo;
you don't know for sure. But the code compiles so it obviously ok!I remember my first attempts at programming and being annoyed that I can't add a string and an int; ever since that little bit of housekeeping of using types made sense to me and I can clearly see how it eliminates entire classes of errors.
I find it more painful to read code that has too many type annotations. I also find it painful to read code that has too few, so I'd argue there's a bit of an art to it.
But languages that have type inference but allow type annotations at least allow you to try to hit that balance.
Type inference doesn't make these errors go away.
And about your other point, it's unfair to look at just a simple case of writing "string" or not as the only thing inference provides. Although I'd argue that leaving out types where possible helps readability-- it's really the more elaborate cases or intermediate steps during a longer transformation that inference helps with. Not to mention the fact that inference in closures is also really nice.
Generally, I prefer being able to read a line of code and understanding exactly what it does. If I need an IDE and have to repeatedly try to find the definition of something then, in my opinion, that's wasting my time.
C++'s 'auto' is really useful but it's over-used IMO. I think that there's a belief that if you're not using 'auto' everywhere then you're not writing 'modern' C++. Just becuase your code compiles doesn't necessarily mean it's correct.
I'd never have believed it myself, but find myself using acronyms instead of variable names when the type allows it.
void foo(MyType mt, const MyOtherType& mot);
It's the variable names that are the noise, types are everything. And no, it's not Hungarian notation either in case anyone suggests it!However, it maybe doesn't work that well with things like class member names. YMMV
using B64String = std::string;
B64String encode(const std::string& text);
std::string decode(const B64String b64);