[webkit-dev] [webkit-reviewers] usage of auto

Darin Adler darin at apple.com
Tue Jan 10 21:49:25 PST 2017


> On Jan 10, 2017, at 9:46 PM, Simon Fraser <simon.fraser at apple.com> wrote:
> 
> auto countOfThing = getNumberOfThings();
> ASSERT(countOfThing >= 0);  // Can’t tell by reading whether the ASSERT is assured at compile time if countOfThing is unsigned

I understand wanting to know, but I am not certain this is a bad thing.

> auto thingLength = getLengthOfThing();
> IntSize size(thingLength, 2); // Can’t tell by reading if thingLength is LayoutUnit or float and thus truncated here.

Makes total sense to me. This is a bad pattern.

> Another common issue in code I’m not familiar with is something like:
> 
> auto fancyStyleThing = styleMagic.styleThingForDoohicky()
> 
> where it maybe obvious to the author what the type of fancyStyleThing is, but without looking at StyleMagic::styleThingForDoohicky() I have no idea what it is, and Xocde doesn’t help me. You argue above that maybe I don’t need to know the exact type, but often I do if I’m trying to figure out how various components relate to each other, rather than studying the logic of one specific function.

If the type of fancyStyleThing was given here it would not tell you the type of styleThingForDoohicky; it would tell you what type we are assigning to but there could be a type conversion.

— Darin


More information about the webkit-dev mailing list