On Tuesday 2015-06-02 13:43 -0700, Martin Thomson wrote: > On Tue, Jun 2, 2015 at 1:35 PM, Kyle Huey <m...@kylehuey.com> wrote: > >> auto len = aArray.Length(); > >> auto display = GetStyleDisplay()->mDisplay; > >> > >> It can save having to look up whether aArray.Length() returns size_t > >> (I sure hope it does, though) or whether mDisplay is uint8_t or > >> uint16_t. > > I have no sympathy for this. If you had a decent IDE, the IDE could > do that lookup for you, but don't force the reader/reviewer of your > code to do that. Code is read many more times than it is written.
My assumption was that this would be for cases where neither the reader nor writer is likely to care about which integral type it is, and also cases that are near the threshold for whether to repeat (in source code or perhaps only in execution) an expression or to put the result of that expression in a variable. For example: auto display = mStyleDisplay->mDisplay; if (frame->IsFrameOfType(nsIFrame::eLineParticipant) || nsStyleDisplay::IsRubyDisplayType(display) || mFrameType == NS_CSS_FRAME_TYPE_INTERNAL_TABLE || display == NS_STYLE_DISPLAY_TABLE || display == NS_STYLE_DISPLAY_TABLE_CAPTION || display == NS_STYLE_DISPLAY_INLINE_TABLE) { ... where most users would explicitly write mStyleDisplay->mDisplay, but in this case it seems nicer to stick it in a variable than write mStyleDisplay->mDisplay four times over. Remember that if 'auto' is forbidden, people might get around it by not using a variable at all (and instead repeating the expression) rather than by writing the type explicitly on the variable... and this doesn't provide type information. The cases I'm talking about are ones where we're near the threshold between repeating the expression or putting its value in a variable. -David -- 𝄞 L. David Baron http://dbaron.org/ 𝄂 𝄢 Mozilla https://www.mozilla.org/ 𝄂 Before I built a wall I'd ask to know What I was walling in or walling out, And to whom I was like to give offense. - Robert Frost, Mending Wall (1914)
signature.asc
Description: Digital signature
_______________________________________________ dev-platform mailing list dev-platform@lists.mozilla.org https://lists.mozilla.org/listinfo/dev-platform