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

Maciej Stachowiak mjs at apple.com
Fri Jan 3 13:45:48 PST 2014

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

>> It might also cover smart pointer usage like your example and multiline expansions of setSize(foo->size()).
>> - Use "auto" when type is obvious for people with basic familiarity with a subsystem:
>> auto& style = renderer.style();
> I don't agree that "basic familiarly with subsystem" is a good criterion. One shouldn't need even basic familiarity with style system to see whether code leaks, introduces refcount thrashing, or copies too much. Using auto tends to make such mistakes much more opaque.
> Raising artificial barriers between subsystems would be really unfortunate, as people tend to work on bugs in many areas.

I don't have a strong view on the other examples, but I agree that "obvious for people with basic familiarity with a subsystem" is a bad criterion. In addition to the reasons you stated, even for people who are familiar this means more to keep in your head instead of to see on the page. While keeping track of such a thing may be trivial for an expert, having to track more trivial things in your working memory the less will eventually reduce your ability to track additional untracked things.


More information about the webkit-dev mailing list