[webkit-dev] [webkit-reviewers] usage of auto
ggaren at apple.com
Thu Jan 12 10:37:45 PST 2017
>> e.g. I think this is great:
>> auto ptr = std::make_unique<Foo>(bar);
>> Proposed rule: if the type is obvious because it's on the line, then auto is good.
>> auto i = static_cast<int>(j);
>> auto foo = make_foo();
>> auto bar = something.get_bar(); // Sometimes, "bar" is obvious.
> I'm not sure I agree with this style. There are times where the type of an auto variable is obvious-enough, but it's almost never more obvious than actually writing out the types.
In the first case, static_cast<int>, the type is written out on the same line. Same goes for other casts, make_unique<T>, and so on. Would you accept auto in those cases? If not, what benefit do you get from seeing the type twice on one line?
I think the second and third cases are somewhat rare in WebKit, and I might agree against using auto. For example:
auto* context = something.context();
context->setThing(thing.get()); // I need to research why context->thing is allowed to be a raw pointer, but I don’t know what context is.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the webkit-dev