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

Brent Fulgham bfulgham at apple.com
Fri Jan 3 09:54:15 PST 2014


Hi antti,

On Jan 3, 2014, at 4:12 AM, Antti Koivisto <koivisto at iki.fi> wrote:

> If we start making rules I'd add the following:
> 
> - Use "auto" when the type name is already mentioned on a line:

+1

> - Use "auto" when the type is irrelevant. This covers things like iterators and adapter classes:

+1

> - Use "auto" when type is obvious for people with basic familiarity with a subsystem:
> 
> auto& style = renderer.style();

I think this is the crux of the argument against using ‘auto’.  Few of us are experts in all parts of the system, so it’s not clear why type is returned here.

My personal preference is to use auto, and rely on the IDE to show me what the actual type is when I view the code.

However, this does not work well when using our code review tools, since there is no ‘type overlay’ available to show us what specific type is being used in this case. So I can understand the argument against using ‘auto’ in this circumstance.

-Brent





More information about the webkit-dev mailing list