[webkit-dev] When to use "auto"? (I usually consider it harmful)

Brent Fulgham bfulgham at apple.com
Thu Jan 2 14:06:48 PST 2014


On Jan 2, 2014, at 1:54 PM, Filip Pizlo <fpizlo at apple.com> wrote:

> I think the goal should be that if you do introduce a temporary variable for some reason, then being explicit about its type is better.  Consider that in your second example, there might be 200 lines of code between the call to optimalSize() and the call to setSize().  I that case, we're essentially choosing between having the code reader see this:
> 
>     auto newSize = optimalSize();
> 
> or this:
> 
>     CGSize newSize = optimalSize();

I’m not sure that having the temporary created 200 lines before it was used would be improved with either of these cases! ;-)

Allowing the compiler to infer type seems like a big win, for all the same reasons it is for SML and other Hindley-Milner languages. Why must I manually enter stuff that the compiler should be able to determine for me?

Our development environments should be capable of showing us the resulting ‘auto’ type, so I feel like requiring explicit type declarations are a step backwards.

-Brent


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.webkit.org/pipermail/webkit-dev/attachments/20140102/da086c3e/attachment.html>


More information about the webkit-dev mailing list