[webkit-dev] When to use "auto"? (I usually consider it harmful)
akling at apple.com
Sat Jan 4 09:10:36 PST 2014
On Jan 4, 2014, at 4:14 PM, Alex Christensen <alex.christensen at flexsim.com> wrote:
> Call me an extremist, but I would be in favor of a complete ban on auto. I've been involved in another project deciding to not use auto at all. It forces programmers to be explicit and careful, it shows the effects of type changes with compiler errors (exposing bugs better), and it's easy to enforce with no debate.
I don’t agree that this is a good thing.
My favorite thing about “auto" is how it automatically takes advantage of
functions getting narrower return types, e.g when changing something in
WebKit to return Element instead of Node. If all call sites are using “auto”,
they may now generate more efficient code (avoiding isElementNode() checks,
FINAL overloads, etc.) without having to touch the source.
Being explicit and careful about this translates to a bunch of busywork
which boring at best and error-prone at worst.
More information about the webkit-dev