<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On 3 December 2013 08:43, Andrei Alexandrescu <span dir="ltr"><<a href="mailto:SeeWebsiteForEmail@erdani.org" target="_blank">SeeWebsiteForEmail@erdani.org</a>></span> wrote:<br>
</div><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"><div class="im">On 12/2/13 4:19 AM, Manu 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">
The problem is that virtual is irrevocable. It can't be removed without<br>
breaking the API<br>
</blockquote>
<br></div>
Here we go again. No, that's not the problem. A similar issue goes about final.</blockquote><div><br></div><div>You can safely add virtual to a function where it wasn't previously present without breaking code.</div>
<div><br></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"><div class="im">
<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">
, which means it's not possible to optimise a library in<br>
that way at any time after it has already been released to the wild. The<br>
converse is not true.<br>
</blockquote>
<br></div>
Conversely final makes it impossible tweak behavior after the library has been released in the wild. You could reasonably argue that you care more about performance optimization than tweaking behavior.</blockquote><div><br>
</div><div>If you're making the kind of library where you want everything to be overridable, writing 'virtual:' at the top is easy. Do that, you're happy, and your intentions are made explicit, and there's also no room for error.</div>
<div>It's nowhere near as simple approaching from the other angle, extremely prone to human error, and if a mistake is made, it it's a breaking change any time you want to fix it.</div><div><br></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"><div class="im">
<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">
It has also been agreed that there is very little the compiler/optimiser<br>
can do to help.<br>
</blockquote>
<br></div>
Same goes about "virtualizing" final.</blockquote><div><br></div><div>What?</div><div><br></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">
<div class="im">
<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">
It's a dangerous default,<br>
</blockquote>
<br></div>
How is it "dangerous"?</blockquote><div><br></div><div>Because it's a breaking change. You can't add final after it's ever seen the light of day. No code is fully optimal after revision 0.01b, people always make mistakes, or react to feedback.</div>
<div>Library authors are always very apprehensive to make breaking changes to their libs, so it's very hard to get things fixed.</div><div>It also requires bumping the major version with semantic versioning to make performance tweaks, and library authors don't like to do that if they can avoid it. It creates a situation where it's very hard to get fixes.</div>
<div><br></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"><div class="im">
<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">
it's got absolutely nothing to do with "I<br>
don't want to type final" as you helpfully simplified it. You can type<br>
'virtual:' at the top, and you're set.<br>
</blockquote>
<br></div>
Can't _you_ type 'final:' at the top and be set? Why is it that, to paraphrase a recent crazy twitter flamewar (<a href="http://goo.gl/h9NMxK" target="_blank">http://goo.gl/h9NMxK</a>), your Thanksgiving is more important than everybody else's?</blockquote>
<div><br></div><div>No. Classes have virtual functions, that's the point. So you have to micro manage it.</div><div>There is not much sense in a class with 'final:', there is sense in a class with 'virtual:', if you want to write your code that way, and the intention is made explicit, which is rarely a bad thing.</div>
<div><br></div><div>With virtual-by-default, there is strong tendency to leave it in it's default state (everything virtual) because it 'just works', and there's no warnings or compile errors to remind you what you've committed to.</div>
<div>What I mean is, the author of the code never deliberately made a _choice_, but they have (probably unknowingly) made a strong commitment. If you're a library author, you can't correct it later without bumping the major version, and risk breaking client code.</div>
<div><br></div><div>I don't have thanksgiving; you're welcome to it.</div><div>I don't see the parallel, I don't consider this a flamewar.</div><div><br></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">
<div class="im">
<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">
Again, the converse doesn't<br>
stand, you can't practically type 'final:' at the top since there will<br>
inevitable by SOME virtual methods.<br>
</blockquote>
<br></div>
Group them before the final: or go through the trouble of typing final { ... }.</blockquote><div><br></div><div>Just type 'virtual:' at the top. Much simpler.</div></div></div></div>