www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Can D "prevents segfaults, and guarantees thread safety"?

reply mahdi <xemailpro yahoo.co.uk> writes:
A selling point of Rust language is that it "prevents segfaults, 
and guarantees thread safety". Is there a library in D language 
which provides same features?
Feb 22 2016
next sibling parent Adam D. Ruppe <destructionator gmail.com> writes:
On Tuesday, 23 February 2016 at 04:28:14 UTC, mahdi wrote:
 A selling point of Rust language is that it "prevents 
 segfaults, and guarantees thread safety". Is there a library in 
 D language which provides same features?
The core d runtime (including the garbage collector) does such things. GC, when used pervasively, eliminates use-after-free bugs. Array bounds checking eliminates buffer overflow bugs. Automatic initialization of variables covers random pointers that way. Those are the sources of most security problems in C code (though not most segfaults - null is still there, but null usually isn't a security problem on desktop and server hardware (idk about phones)). .net, Java, D, javascript, python, the list goes on, these languages all do pretty good jobs at taking care of this class of bug. It isn't something unique to Rust. (though garbage collection is typically a major part of the standard solution, and Rust does that differently, that's why it is interesting, not that it solves these problems, but that it does it a bit differently than the accepted mainstream solution.) Thread safety is a bit trickier but D's use of default thread-local data tries to attack it too. The problem with D's solution is too many people recommend turning them off in the name of performance benchmarks :(
Feb 22 2016
prev sibling parent Chris Wright <dhasenan gmail.com> writes:
On Tue, 23 Feb 2016 04:28:14 +0000, mahdi wrote:

 A selling point of Rust language is that it "prevents segfaults,
 and guarantees thread safety". Is there a library in D language which
 provides same features?
D is more for providing safe defaults than for entirely preventing problems. The safe annotation is intended to provide more guarantees. It allows you to dereference null, but otherwise it prevents memory errors (aside from some outstanding issues around casting to and from void[]).
Feb 22 2016