classes structs

Jonathan M Davis jmdavisProg at gmx.com
Sat Sep 15 04:05:47 PDT 2012


On Saturday, September 15, 2012 03:58:50 Jonathan M Davis wrote:
> You can like it or not, but separating structs and classes and making
> classes reference types on the heap is a design decision based on the best
> practices and common bugs in C++. And it works very well. Upon occasion, it
> can be limiting (hence why we have std.typecons.scoped), but I don't think
> that you're going to find very many D programmers who think that the
> separation of structs and classes was a bad idea.

You should keep in mind that D's general philosophy is to make the defaults 
safe but to allow you to do more powerful, dangerous stuff when you need to. 
The result is that it's just as powerful as C++ when you need it to be but 
that it's a lot safer in general, meaning that you're going to have fewer bugs 
in your code.

A prime example of this is the fact that all variables are default-
initialized. This way, you never have problems with variables being 
initialized to garbage, which can cause non-deterministic, hard-to-track-down 
bugs. But if you really need the extra speed of a variable not being 
initialized when it's declared, then you can initialize it to void. e.g.

int i = void;

This makes it so that code is far less error-prone in general while still 
allowing you to have the same down to the metal speed that C/C++ offers when 
you really need it. And it's that philosophy which governs a lot of D's 
features.

- Jonathan M Davis


More information about the Digitalmars-d mailing list