On 01/05/2012 12:54 AM, Manu wrote:
On 5 January 2012 01:40, Timon Gehr <timon.g...@gmx.ch
<mailto:timon.g...@gmx.ch>> wrote:
On 01/05/2012 12:26 AM, Manu wrote:
You just missed a big discussion on IRC about this, where I
think I made
some fair points that people actually agreed with.
On 1/4/2012 10:53 AM, Manu wrote:
Oh, and virtual-by-default... completely unacceptable for a
systems language.
most functions are NOT virtual, and finding the
false-virtuals
while
optimising will be extremely tedious and time consuming.
The only reason to use classes in D is for polymorphic
behavior -
and that means
virtual functions. Even so, a class member function will be
called
directly if
it is private or marked as 'final'.
Is this true? Surely the REAL reason to use classes is to
allocate using
the GC?
You can allocate any type using the GC.
Aren't struct's allocated on the stack, and passed to functions by
value? Do I need to start using the ref keyword to use GC
allocated structs?
No.
An easy way to find functions that are not overridden (what you
called false virtuals) is to add:
final:
at the top of your class definition. The compiler will give you
errors for any functions that need to be virtual.
If you don't want polymorphic behavior, use structs instead.
Struct
member
functions are never virtual.
I have never written a class in any language where the ratio of
virtual
to non-virtual functions is more than 1:10 or so... requiring
that one
explicitly declared the vastly more common case seems crazy.
Are you sure that is the case?
In my code, most class member functions are true virtual.
Here's one I'm working on right now (C++).
Base class for a UI system, surely one of the most heavily polymorphic
types of code one can imagine.
Apparently that is not true.
Count the virtuals... http://pastebin.com/dLUVvFsL
9/~65 approx 1:6.