A D vs. Rust example

H. S. Teoh hsteoh at qfbox.info
Thu Oct 27 20:07:13 UTC 2022


On Thu, Oct 27, 2022 at 07:29:15PM +0000, ryuukk_ via Digitalmars-d wrote:
> On Thursday, 27 October 2022 at 17:37:59 UTC, Quirin Schroll wrote:
> > Imagine how much more attractive D would be to OO crowd if it had
> > first-class value type boxing, generics with variance and wildcards,
> > and all the other OO stuff modern OO-fist languages offer. Using
> > Java and C#, it feels like D only has the bare minimum to call
> > itself object-oriented.

IMO, D doesn't really need any of the heavyweight OO features because
typical idiomatic D code doesn't rely heavily on OO, but on other idioms
like structs for by-value exchange of data, ranges, and DbI.  When the
entire language is predicated on OO, like in Java, then you need all the
advanced machinery to make OO more tolerable.  But when you can simply
step outside of the OO box and solve things with other tools, then there
isn't a big need for heavy OO machinery.


> > There was some talk (by Átila, IIRC) that having first-class classes
> > and OO in D was a design error. I have no idea whether there is
> > actually a plan to fade those out improve them to be competitive on
> > that front.

I think it's a bit extreme to call OO support a design error... but I'd
say it's true that in most of my D code, I find little need for OO.
D-centric idioms like structs, ranges, DbI, metaprogramming, CTFE,
already cover most of the areas that languages like Java use OO for; as
a result, the role of OO in D is much narrower than in Java.


> Go annihilated both Java/C# and became the cloud native language
> without the OOP features
> 
> Rust is becoming the system language of choice without the OOP
> features
> 
> Zig is making a dent without the OOP features
> 
> The more OOP you put in a language, the worst it becomes

I disagree.  OOP itself isn't bad; it has its place.  For certain
things, like programming widget hierarchies, OO totally makes sense, and
I'd even recommend using OO idioms for that.

What's bad is the fallacious philosophy that OO is the be-all and
end-all of programming paradigms (the fanboy attitude that unfortunately
permeated the scene in the early days of Java), where you try to
shoehorn OO into everything else where it doesn't fit, ending up with
ridiculous things.  Like static singleton "classes" with static methods,
whose sole purpose of existence is to give you bragging rights that your
code is fully OO-certified, without "bad" things like global functions
and global variables. (Spoiler: you just used them, only under a
different name.) Sometimes, I daresay even oftentimes, an in-register
int or by-value struct is good enough (or even better); there is no need
to carry around that excess baggage needed for runtime polymorphism and
inheritance, just so you can brag that "everything is an object" and
OO-approved and certified.


> C# is adding more functional and low features because OOP features
> doesn't cut it
> 
> OOP is nice only when kept very simple and minimal

I'd say OOP works very well -- within its own niche. There are many more
things in programming than are in the little garden of OO.


T

-- 
Two wrongs don't make a right; but three rights do make a left...


More information about the Digitalmars-d mailing list