<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><br><div><div>On Jan 2, 2014, at 2:55 PM, Brent Fulgham &lt;<a href="mailto:bfulgham@apple.com">bfulgham@apple.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">Hi Filip,<div><br><div><div>Coming back to your earlier example:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><div>&nbsp; &nbsp; auto newSize = optimalSize();</div><div dir="auto">vs:</div></div></blockquote><blockquote type="cite"><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><div dir="auto">&nbsp; &nbsp; CGSize newSize = optimalSize();</div></div></blockquote><br></div><div>If I understand your argument, you feel that the explicit CGSize declaration helps the reader because it makes the return value of optimalSize() explicit.</div><div><br></div><div>However, that declaration is only stating the type that the author *thinks* optimalSize() returns. &nbsp;There is nothing to guarantee that optimalSize() returns a CGSize; only that it returns something that the compiler can turn into a CGSize through some set of casts.</div></div></div></blockquote><div dir="auto"><br></div><div dir="auto">Yes, C++ offers some interesting escape hatches from the type-system so this documentation (i.e. the use of "CGSize" to ascribe a type to newSize) needs to be interpreted carefully. &nbsp;It's not guaranteeing that optimalSize() returns a CGSize, only that it returns something that is coercible to a CGSize. &nbsp;Also, it does guarantee that newSize is indeed a CGSize and not anything else.</div><div dir="auto"><br></div><div dir="auto">To me, that's still better than no information at all, which is what "auto" does.</div><br><blockquote type="cite"><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div><div><br></div><div>The code stating CGSize could have been correct at one point, but the return type of optimalSize might have been changed to some similar type without anyone noticing.</div><div><br></div><div>Using ‘auto’ doesn’t seem to make this situation any worse.</div></div></div></blockquote><div><br></div><div>It conveys zero information, whereas declaring the variable as CGSize does convey meaningful information about optimalSize(), newSize, and the kinds of things you could do with newSize.</div><br><blockquote type="cite"><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div><div><br></div><div>In fact, although Sutter’s suggestion of:</div><div><br></div><div><span class="Apple-tab-span" style="white-space: pre;">        </span>auto newSize = CGSize { optimalSize(); }</div><div><br></div><div>looks gross to my eye, it might be a useful approach because it would force the compiler to complain if we were returning something that was not explicitely a CGSize type.</div></div></div></blockquote><div><br></div><div>I know this doesn't apply to CGSize, but the approach we've been using in JSC is to make all unary constructors 'explicit' and to prefer wrapper classes over typedefs, even for primitive values. &nbsp;This also has the effect of preventing many implicit coercions, and it carries some other benefits also:</div><div><br></div><div>1) It means that you don't have to use this gross syntax.</div><div><br></div><div>2) It controls the kind of coercions that can happen even in cases where there is no variable, like setSize(optimalSize()).</div><div><br></div><div>-Filip</div><div><br></div><br><blockquote type="cite"><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div><div><br></div><div>-Brent</div></div></div></blockquote></div><br></body></html>