<div dir="ltr">On Tue, Jun 18, 2013 at 6:38 PM, Darin Adler <span dir="ltr"><<a href="mailto:darin@apple.com" target="_blank">darin@apple.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
Lets bike shed!<br>
<br>
For some time, functions with names like fooIfExists and ensureFoo have been bothering me. I find both names kind of opaque and unpleasant. Here’s an example:<br>
<br>
StyleResolver* styleResolverIfExists();<br>
StyleResolver* ensureStyleResolver()<br>
<br>
What do you think of these names instead?<br>
<br>
StyleResolver* optionalStyleResolver();<br>
StyleResolver& requiredStyleResolver();<br></blockquote><div><br></div><div>requiredStyleResolver sounds as if it's a special (required) type of a style resolver as opposed to the caller requiring it. Why don't we call it requireStyleResolver() instead?</div>
<div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Note also that I think the requiredStyleResolver function should return a reference so nobody is tempted to do null checks.</blockquote>
<div><br></div><div>Sounds like a great idea.</div><div><br></div><div>On Tue, Jun 18, 2013 at 7:03 PM, Emil A Eklund <span dir="ltr"><<a href="mailto:eae@chromium.org" target="_blank">eae@chromium.org</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div class="im">On Tue, Jun 18, 2013 at 6:38 PM, Darin Adler <<a href="mailto:darin@apple.com">darin@apple.com</a>> wrote:<br>
> What do you think of these names instead?<br>><br>> StyleResolver* optionalStyleResolver();<br>> StyleResolver& requiredStyleResolver();<br><br></div>+1, much clearer and the pointer vs reference makes it even more so.<br>
Perhaps enough so that the required prefix could be dropped:<br><br>StyleResolver* optionalStyleResolver();<br>StyleResolver& styleResolver();</blockquote><div><br></div><div>I think it's important to communicate the runtime cost of ensuring the existence of the object. </div>
</div><div><br></div><div>- R. Niwa</div><div><br></div></div></div></div>