<div dir="ltr">On Tue, Jun 18, 2013 at 6:38 PM, Darin Adler <span dir="ltr">&lt;<a href="mailto:darin@apple.com" target="_blank">darin@apple.com</a>&gt;</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&amp; requiredStyleResolver();<br></blockquote><div><br></div><div>requiredStyleResolver sounds as if it&#39;s a special (required) type of a style resolver as opposed to the caller requiring it.  Why don&#39;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">&lt;<a href="mailto:eae@chromium.org" target="_blank">eae@chromium.org</a>&gt;</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 &lt;<a href="mailto:darin@apple.com">darin@apple.com</a>&gt; wrote:<br>

&gt; What do you think of these names instead?<br>&gt;<br>&gt;     StyleResolver* optionalStyleResolver();<br>&gt;     StyleResolver&amp; 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&amp; styleResolver();</blockquote><div><br></div><div>I think it&#39;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>