If you had money to place for a bounty, what would you choose?

Adam D. Ruppe destructionator at gmail.com
Mon Dec 2 05:50:34 PST 2013


On Monday, 2 December 2013 at 11:14:58 UTC, Namespace wrote:
> final by default is far more efficient than virtual by default. 
> So final by default is preferable.

The *whole point* of classes is to have virtual functions. If you 
don't want them, don't write class methods! Use structs or UFCS 
instead.

Perhaps a counter argument is that the whole point of 
*interfaces* is virtual functions, and classes just implement 
them and thus ought to be final, if you want virtual stuff go 
through the interface.

But, regardless, I think the real problem here isn't virtual by 
default. The real problem is there's things written as class 
methods that really shouldn't me methods at all. The ideal 
"method" is actually a UFCS function that operates on the 
interface, without touching any private state at all. Next best 
is a  UFCS function that works on the class and needs private 
state.

The only time it, at least ideally speaking, should be in the 
class itself is if it has something to do with implementing 
interfaces. And that means virtual generally makes sense.


More information about the Digitalmars-d mailing list