Proposal: Type inference for variable definition/initialization using the 'auto' keyword.

Lawrence Kesteloot lk at teamten.com
Fri May 15 22:09:30 PDT 2009


Reinier Zwitserloot wrote:
> That's arbitrary. You can't just hand-wave and say its 'only used in passing
> and I don't care' in one situation but in the other situation it all of a
> sudden becomes crucial.

I'm not going to be able to use logic to convince you of the
difference, but for me it's there. The original "getX().getY().getZ()"
may as well have been a utility function "getXYZ()". It's an opaque
expression and I don't care about its intermediate types. The chained
"append()" is an idiom and the type is the same throughout. But by the
time I'm putting a reference into a named (even final) variable, then
I want to use it a bunch and I want to know its type. As an author I
want the compiler to double-check my work, and as a reader I want the
explicit documentation.

>  2. Less noise by expanding the existing mechanism of offering the
> programmer to, at their discretion, elide explicit type information.

What's noise to you is documentation to me.

Perhaps one day I'll write a large Scala program on a team with others
and find that the "val" declarations everywhere (which is essentially
what you're suggesting) are perfectly readable and don't impede my
ability to browse quickly through code when looking for problems. Then
I'll change my mind about this.

Lawrence



More information about the coin-dev mailing list