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

Alexey Proskuryakov ap at webkit.org
Wed Jan 11 09:41:26 PST 2017


There are two considerations which make me skeptical that auto is a good thing.

1. There are many smart pointer types in C++, and ignoring pointer types is very error prone. Others have mentioned std::optional, and mistakes being made with RefPtrs. I even saw a case where a review comment that suggested switching to auto, but it would have introduced memory corruption if followed.

Some specific cases of this may become irrelevant as PassRefPtr goes away, but I don't think that there is any expectation that smart pointers in general are going away.

2. I also find that types in code are an important part of documenting how it is supposed to work. In a way, these are read-time assertions. An assertion can be wrong and they are compiled out in release builds, yet they prove to be highly valuable anyway. Similarly, a type can be wrong, but it tells me as the reader what the author thinks their code is doing, and lets me focus on other parts of it for the first pass at least.

A very similar kind of type agnostic coding has always been used in templates, and it feels like a well established belief that it takes engineers with high levels of expertise to write generic code in templates. And if it's harder, I don't see why using these techniques all over the place is beneficial.

- Alexey


> 11 янв. 2017 г., в 9:15, Darin Adler <darin at apple.com> написал(а):
> 
> OK, you didn’t convince me but I can see that your opinions here are strongly held!
> 
> — Darin
> _______________________________________________
> webkit-dev mailing list
> webkit-dev at lists.webkit.org
> https://lists.webkit.org/mailman/listinfo/webkit-dev


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.webkit.org/pipermail/webkit-dev/attachments/20170111/21157321/attachment-0001.html>


More information about the webkit-dev mailing list