<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jan 12, 2017, at 10:37 AM, Geoffrey Garen <<a href="mailto:ggaren@apple.com" class="">ggaren@apple.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><blockquote type="cite" class=""><div class=""><div dir="auto" class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="">e.g. I think this is great:</div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px" class=""><div class=""><font face="monospace, monospace" class="">auto ptr = std::make_unique<Foo>(bar);</font></div></blockquote><div class="">Proposed rule: if the type is obvious because it's on the line, then auto is good.</div><div class="">Similarly:</div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px" class=""><div class=""><font face="monospace, monospace" class="">auto i = static_cast<int>(j);</font></div></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px" class=""><div class=""><font face="monospace, monospace" class="">auto foo = make_foo();</font></div></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px" class=""><div class=""><font face="monospace, monospace" class="">auto bar = something.get_bar(); // Sometimes, "bar" is obvious.</font></div></blockquote></div></div></blockquote>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 <i class="">never</i> more obvious than actually writing out the types.</div></div></blockquote><div class=""><br class=""></div>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?</div></div></div></blockquote><div><br class=""></div>My reason I don't like this style is it slightly changes how I read code. I typically look at the lhs of an expression to get its type.</div><div>Now, I may have to look at the lhs, and maybe at some compound expression on the rhs. I just don’t see the point of this</div><div>to save a few characters.</div><div><br class=""></div><div>For cases like jsDynamicCast, std::make_unique, etc, I also have to know what those functions do. This is obvious to experienced JSC/C++ developers, but maybe not to all newcomers to the code base.</div><div><br class=""></div><div>All that said, this usage of auto probably bothers me the least out of all the usages I don’t like.</div><div><br class=""></div><div>- Saam</div><div><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><br class=""></div><div class="">I think the second and third cases are somewhat rare in WebKit, and I might agree against using auto. For example:</div><div class=""><br class=""></div><div class="">RefPtr<T> thing;</div><div class="">auto* context = something.context();</div><div class="">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.</div></div></div></blockquote><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><br class=""></div><div class="">Geoff</div></div>_______________________________________________<br class="">webkit-dev mailing list<br class=""><a href="mailto:webkit-dev@lists.webkit.org" class="">webkit-dev@lists.webkit.org</a><br class="">https://lists.webkit.org/mailman/listinfo/webkit-dev<br class=""></div></blockquote></div><br class=""></body></html>