Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

What does it bring over modern C++? Why would you want to use it?


- Nearly instant compile times

- GC by default, manual memory management where and when you need it with no loss of efficiency

- Better metaprogramming

- Does not compromise on things a C++ coder would care about (speed, efficiency, deterministic behavior, etc.)

The language is led by Andrei Alecsandrescu and Walter Bright, two C++ core language veterans


Modules (Alone would be enough imo)



I don't view it's counterpart to be C++ these days; dlang is a GC'd language, so it's actually probably fairer to compare it to Go instead.


It is a clear alternative to C++. The GC is optional.


Is it? Last time I checked a few years ago there were huge caveats to allocation Objects on the stack (I forget what they were) so unless something's drastically changed this doesn't seem like an honest assessment.


The pitfalls aren't really any different than C++... either use some kind of smart pointer, or use caution not to escape references to stack memory (very easy mistake to make in D) or slice up the object by value (very difficult to do in D) and you'll be fine.

The built-in `scope` syntax is deprecated (though making a comeback recently as more stuff gets implemented around it), but you can also do a library type fairly easily, just slightly heavier in syntax (you need to prepare the memory and construct the object in two separate lines) or prep work (write a struct which does both).


If you want to allocate an object on the stack, then use std.conv : emplace and alloca. This(https://wiki.dlang.org/Memory_Management#Allocating_Class_In...) method also exists but is on the road to deprecation


Oberon, Modula-3 and System C# among many others would beg to differ.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: