auto: useful, annoying or bad practice?
Giles Bathgate
giles.bathgate at gmail.com
Mon Apr 30 21:31:48 UTC 2018
On Monday, 30 April 2018 at 21:11:07 UTC, Gerald wrote:
> I'll freely admit I haven't put a ton of thought into this post
> (never a good start), however I'm genuinely curious what
> people's feeling are with regards to the auto keyword.
>
> Speaking for myself, I dislike the auto keyword. Some of this
> is because I have a preference for static languages and I find
> auto adds ambiguity with little benefit. Additionally, I find
> it annoying that the phobos documentation relies heavily on
> auto obscuring return types and making it a bit more difficult
> to follow what is happening which gives me a bad taste for it.
>
It takes some getting used to. Type inference is useful because
often you don't care/know, or want to type out the full name of
the type for every variable. It does, however, assume that the
developer can also do type inference (when/if you need to know
the type). When it's not clear what the type is by looking at the
right-hand side perhaps the codebase has bigger problems.
functions that return auto are a bit odd IMHO, that is a feature
unique to D. But I don't have a problem with type inference in
general, all language have it including C#, C++, TypeScript,
Rust...etc not that that is a good argument, but just that its
something you have to get used to, because people will use the
feature whether you like it or not.
More information about the Digitalmars-d
mailing list