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

Simon Fraser simon.fraser at apple.com
Fri Jan 3 10:53:22 PST 2014

On Jan 3, 2014, at 10:11 AM, Alexey Proskuryakov <ap at webkit.org> wrote:

> I'm not Geoff, yet I'd like to offer my perspective on the specific examples you provided.
> 03 янв. 2014 г., в 4:12, Antti Koivisto <koivisto at iki.fi> написал(а):
>> auto& cell = toRenderTableCell(*renderer); // right
>> RenderTableCell& cell = toRenderTableCell(*renderer);  // wrong
> I can't agree with this example. With auto, I don't know if it's a raw pointer, a reference, or a smart pointer (we have toXXX functions that return all of those). I also cannot Cmd+click on anything to go to the class definition, and when I Cmd-click on toRenderTableCell, I presumably get into some unreadable macro.
> Overall, auto makes the code very opaque here.

I agree. I think use of auto makes code you’re unfamiliar with much harder to follow, and makes getting to the type declaration one more Command-click away. Better tools integration would help; if I could hover over the “auto” had have Xcode show me, in a tooltip, what type the compiler will infer, then I’d be more willing to see wider use of auto.


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

More information about the webkit-dev mailing list