D 2015/2016 Vision?

Jonathan M Davis via Digitalmars-d digitalmars-d at puremagic.com
Tue Oct 6 13:31:56 PDT 2015


On Tuesday, 6 October 2015 at 20:04:06 UTC, jmh530 wrote:
> On Tuesday, 6 October 2015 at 18:43:42 UTC, Jonathan M Davis 
> wrote:
>> In most cases though, just don't use classes. In most cases, 
>> inheritance is a horrible way to write programs anyway, 
>> because it's _horrible_ for code reuse. It definitely has its 
>> uses, but I've found that I rarely need classes in D. I 
>> suspect that far too many folks new to D end up using classes 
>> instead of structs just because they're used to using classes 
>> in C++ or Java or whatever.
>
> What improvements to structs do you think would help people 
> coming from C++/Java most?

I don't think the problem is with structs. The problem is that 
programmers coming from other languages default to using classes. 
The default in D should always be a struct. You use a class 
because you actually need inheritance or because you want to 
ensure that a type is always a reference type and don't want to 
go to the trouble of writing a struct that way (and even then, 
you should probably just write the struct that way). You 
shouldn't use a class as your default for user-defined types in 
D. But because other languages don't have structs quite like D 
does, and you use classes in those other languages, that's what 
most everyone wants to use - at least initially.

It would not surprise me if there are some compiler bugs with 
regards to structs that result in some loopholes that shouldn't 
be there (e.g. with @disable-ing stuff), but on the whole, I 
think that D structs are very well designed as they are. The only 
real issue IMHO is having an init value vs having a default 
constructor, and that's a tradeoff with pros and cons on both 
sides. It does sometimes seem painful to folks coming from C++, 
but on the whole, I think that we're better off for it.

- Jonathan M Davis


More information about the Digitalmars-d mailing list