Why does nobody seem to think that `null` is a serious problem in D?
welkam
wwwelkam at gmail.com
Wed Nov 21 20:15:42 UTC 2018
On Wednesday, 21 November 2018 at 09:20:01 UTC, NoMoreBugs wrote:
> On Tuesday, 20 November 2018 at 15:46:35 UTC, Adam D. Ruppe
> wrote:
>> On Tuesday, 20 November 2018 at 13:27:28 UTC, welkam wrote:
>>> Because the more you learn about D the less you want to use
>>> classes.
>>
>> classes rock. You just initialize it. You're supposed to
>> initialize *everything* anyway.
>
> a fan of classes...on the D forum? I don't get it.
>
> but of course you are right. classes do rock!
>
> In fact, there is not a better programming construct that I am
> aware of, the provides a better 'explicit' mapping from
> external objects to program constructs.
>
> Thank you Kristen and Ole-Johan.
One thing that bugs me in programming is that in different
programming languages the same things are named differently and
things that are named the same are different. For example D`s
slices and C#`s spans are the same thing. C++ string_view might
be considered the same also, but classes in C++ and Java are not
the same thing.
In D classes are reference type and unless you mark them as final
they will have vtable. Lets face it most people dont mark their
classes as final. What all this mean is that EVERY access to
class member value goes trough indirection (additional cost) and
EVERY method call goes trough 2 indirections (one to get vtable
and second to call function(method) from vtable). Now Java also
have indirect vtable calls but it also have optimization passes
that convert methods to final if they are not overridden. If Java
didnt do that it would run as slow as Ruby. AFAIK D doesnt have
such optimization pass. On top of that some people want to check
on EVERY dereference if pointer is not null. How slow you want
your programs to run?
Thats negatives but what benefit classes give us?
First being reference type its easy to move them in memory. That
would be nice for compacting GC but D doesnt have compacting GC.
Second they are useful for when you need to run code that some
one else wrote for your project. Something like plugin system.
[sarcasm]This is happening everyday[/sarcasm]
Third porting code from Java to D.
Everything else you can do with struct and other D features.
More information about the Digitalmars-d-learn
mailing list