auto: useful, annoying or bad practice?
Chris
wendlec at tcd.ie
Sat May 19 12:01:17 UTC 2018
On Friday, 18 May 2018 at 16:25:52 UTC, Neia Neutuladh wrote:
> On Friday, 18 May 2018 at 10:09:20 UTC, Chris wrote:
>> In a way Java has slowly been moving in that direction anyway,
>> cf. this answer [2] that reminded me of D's `auto` return type.
>> [2]
>> https://stackoverflow.com/questions/1348199/what-is-the-difference-between-the-hashmap-and-map-objects-in-java
>
> Except the return type that you wrote in that case tells you
> almost everything you can do with that value. If you specify
> the return type of a function as `auto`, it tells you nothing.
> The Java equivalent would be to return Object.
My point was about implementing an interface you can rely on,
regardless of what auto returns, eg:
auto name = user.name;
user could be anything, but it still has the field / property
'name'.
More information about the Digitalmars-d
mailing list