Why is D unpopular?

forkit forkit at gmail.com
Sat Jun 11 11:24:04 UTC 2022


On Saturday, 11 June 2022 at 10:49:09 UTC, Alexandru Ermicioi 
wrote:
>
> ..
> Welcome to single module per class. Really, I fail to 
> understand what's the problem with having one class per module, 
> and import multiple classes per module using public imports if 
> you desire to import multiple classes at once.
>

The problem I have, is that a class is not considered a proper 
type in D.
If it were, you would be able to define and enforce (at compile 
time) its invariants. As it is, any code in the module (outside 
of the class), can invalidate the invariants.

This is equivalent to D letting you put "wtf!" into an int. Would 
you be happy with that?

i.e Even an int is given better type conformance in D.

The module is not a type!

I do not design my solution around the module. I design it around 
types, and I use the module to bring related types together.

Separate, unrelated types can go in their own module.

In the event a type (and I'm talking about an instatiation of 
class here) - is a standalone type.. sure..it can go it's own 
module, no problem. Makes sense even.

But you don't have to put every int your define into its own 
module, just so the compiler can enforce its invariants. That 
would be crazy.. yes?

A class is just a type - why is it considered less a type than an 
int? (i.e. the only way to protect its invariants, is to put it 
all by itself in its own module.

What utter nonsense!


> While it is not better per your reasoning, it is certainly not 
> worse than others per my experience, and at least better than 
> C++. I'd say on level with Java or a bit higher in 
> functionality and convenience.
>
> Best regards,
> Alexandru.

The module is not a type. You do not design your solution using 
types.

You do not instatiate a module, and start sending it messages, or 
recieve messages from it, or change its behavior, or have it 
change its own behavior.

The module is a just convenient static encapsulation for related 
types.

but you design a program by using types, not modules.




More information about the Digitalmars-d mailing list