3 ms·
The point of `auto` and `:=` is not to "shave off a few seconds of effort manually looking up the return type of bar(), and a few characters typing out the type
by 1ris 5y ago
The point of `auto` and `:=` is not to "shave off a few seconds of effort manually looking up the return type of bar(), and a few characters typing out the type in foo's declaration.", but to help with refactoring.
- cogman10 5y agoYup. This is often a pointed missed by people that don't like type inference. Very often, you care very little about the actual type information that comes back. What you care about is "does this have field xyz" or "Does this contain a iterable of data with field xyz". You don't care if that's some specific type of list or what package that data is contained within. By heavily using type inference, you make it so future changes to where the code lives or even the implementation of that code requires fewer ritual changes throughout a codebase. I don't have to go to a bunch of import locations and change foo.xyz to bar.xyz. It reduces the friction caused by static typing that dynamic type people like to harp on. In general, the only potential downside is a loss of readability. That, IMO, isn't a terribly strong argument. Usually you'll have an IDE that will tell you the types and the people that don't like type inference are usually pretty silent on chained operations (foo().bar().baz()) which technically have the same theoretical downside.