We're #1 on Hacker News at the moment!

H. S. Teoh hsteoh at quickfur.ath.cx
Tue Apr 28 23:02:06 UTC 2020


On Tue, Apr 28, 2020 at 10:28:22PM +0000, Jeff C. via Digitalmars-d wrote:
> On Tuesday, 28 April 2020 at 18:57:23 UTC, H. S. Teoh wrote:
> > I *have* found myself wanting to store one of these ranges sometimes
> > -- that's when I pull out typeof() and let the compiler do the heavy
> > lifting for me.  Seriously, it's 2020, why are we still manually
> > typing out type names?!  If it's already obvious from the context,
> > let the compiler fill it in for me, I have better things to do with
> > my time than to retype stuff that the compiler already knows all too
> > well.
> 
> Indeed. One might get the idea that those who reject auto and the like
> must be quite conservative of modernity and/or masochists.

Don't get me wrong, I despise the philosophy of modernity for the sake
of modernity. Of jumping on the bandwagon because it's the bandwagon.
(But then again, I also despise the philosophy of conservativeness for
the sake of conservativeness, so there's that. :-D)

The real issue here is that we invented machines for the sake of doing
repetitive boring stuff that we don't want to do ourselves; now we have
a machine that's capable of inferring types for us, why would we want to
go back and do the machine's job just for the sake of doing the
machine's job?  What can be automated, should be automated.  Life is far
too short to be squandered on repetitive tasks that machines can do
better, faster, and more reliably than we can.

If anything, I'd say the objections against auto stems more from the
lack of a easy UI to have the machine tell us, at a moment's notice,
what the inferred type is, than anything to do with type inference
itself.  I can sympathize with the frustration that somebody looks at
the docs of some function, sees the return type as 'auto', and the
description doesn't actually tell you what that type is, what you can do
with it, etc..  But if there was a button, say in your IDE or on the
docs website or whatever, next to the 'auto', that you can click and it
comes back with the name of the type, or better yet, a list of
operations / properties you can rely upon to operate on the returned
object, then this particular objection will be null and void.

IOW, the objection isn't so much against auto and type inference itself,
but a symptom of the lack of an easy, accessible way to query the
inferred type (for properties, operations, docs, what-have-you). Type
inference is IMO the way of the future. As we build higher and higher
abstractions on the machine, we really don't want to be fiddling with
the nitty-gritty of actual types every moment.  Let the machine deal
with it for us while we focus on the more important things, like,
y'know, actually making progress in the problem domain, rather than
wasting mental bandwidth micro-managing trifles like what concrete type
some function happens to return is.



T

-- 
Be in denial for long enough, and one day you'll deny yourself of things you wish you hadn't.


More information about the Digitalmars-d mailing list