Why is D unpopular?

forkit forkit at gmail.com
Sat Jun 11 08:51:39 UTC 2022


On Saturday, 11 June 2022 at 08:23:27 UTC, Max Samukha wrote:
>
> Class is *the* unit of encapsulation by any reasonable 
> definition of class-based OOP. You don't create objects of 
> modules (though modules can be viewed as singleton objects). 
> You can argue about the mechanism of sharing the state between 
> objects of different classes, but forcing the programmer to 
> group classes together and share the entirety of their state is 
> not the greatest of options.

+1

also, a class is a type, just like any other type - example an 
int.

when you assign to an int, type checking is done. you cannot put 
"wtf!" into an int! It has invariants to it, and the compiler 
checks these (type checking).

but for some reason, a class doesn't get the same protection - 
not even an option to protect it (from other code in a module).

The module is not a type, it's a unit of encapsulation, and that 
is all it is.

A class is a type, which is much more than just a unit of 
encapsulation.

When a class sets invariants, the compiler must do type checking, 
just as it does with an int, to ensure the invariants are being 
upheld.

When a programming langauges stops treating a class as a type, it 
cannot claim to have support for OOP.


More information about the Digitalmars-d mailing list