Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I believe it should <strong>definitely</strong> depend on the implementation. As implied from your question, barring a completely "always-better" signature, the only sensible thing to do is to choose the signature in a manner that optimizes the current implementation. If you write the interface before the code - take an educated guess, and try to maneuver yourself in such a way that you can wait for a first implementation before you commit to the signature. </p> <p>The operative words here are "first" and "current". What happens if you got it wrong? What happens if at some later stage the signature prevents your code from being optimal? Here's what you can do:</p> <h2>No commitment</h2> <p>If it's soon enough - just change it. It follows from the definition of "no commitment", right?</p> <h2>Committed to API</h2> <p>For a concrete example, assume you chose wrong, and went with this:</p> <pre class="lang-cpp prettyprint-override"><code>virtual void DoStuff(std::string s) = 0; </code></pre> <p>However, as it turns out, no copying needs to be performed (same as your original <code>DoStuff</code> implementation). Here's what you can do:</p> <pre class="lang-cpp prettyprint-override"><code>// stuff.h virtual void DoStuff_Optimized(const std::string &amp; s); virtual void DoStuff(std::string s); // stuff.cc virtual void DoStuff_Optimized(const std::string &amp; s); { // Fast implementation of DoStuff, no copying necessary std::cout &lt;&lt; s.length() &lt;&lt; std::endl; } virtual void DoStuff(std::string s) { DoStuff_Optimized(s); } </code></pre> <p>Existing clients will get inferior performance. New clients can use the <code>Optimized</code> version.</p> <h2>Committed to ABI</h2> <p>There might be nothing you can do at this point, unfortunately. However, if you're <a href="http://techbase.kde.org/Policies/Binary_Compatibility_Issues_With_C++#The_Do.27s_and_Don.27ts" rel="nofollow">careful</a>, you might be able to follow the "Committed to API" action. (In particular, my example will not preserve ABI compatibility).</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload