Hacker News new | past | comments | ask | show | jobs | submit login

There is no quantitative metric for safety and easyness.

If you can afford a garbage collector, D easily wins over Rust. If you really need the safe manual memory management, Rust wins. In between is still a large grey area.




> If you can afford a garbage collector, D easily wins over Rust.

This is the "the only point of the ownership/borrowing model is to avoid GC" myth that I've been working to kill. Rust's model also gets you data race freedom, to name just one other benefit.


There are plenty of reasons why Rust could win outside of requiring safe manual memory management. It is an expression based language with ad-hoc polymorphism, algebraic data types, hygienic macros, first class functions, and race-free concurrency.

I don't use rust because I don't need manual memory management and I require subtype polymorphism for a lot of things, but I choose Scala over D.


Neither Rust nor Scala hold a candle to D in terms of compile-time introspection. You can do things with it that are near unbelievable - "you must ask yourself if some law of nature was broken" quoted from memory in http://dconf.org/2015/talks/alexandrescu.html


Scala developers can do whatever they want or need at compile-time.


> race-free concurrency

Rust's thread model is free from data races (a thread must have exclusive access to a variable in order to write to it), but not from race conditions in general.


Could you give an example of a kind of race conditions allowed in Rust?

(Sorry for a naive question, just thought that a data race and a race condition are synonyms. What else is there to race over if not shared data?)


The "data race" term is jargon (i.e. means more than just "race on data") that specifically refers to unsynchronised concurrent accesses to a piece of memory/resource (where at least one of the accesses is a write), while a race condition is a higher level thing, where things aren't ordered the way one intends, even if they have the appropriate "low-level" synchronisation to avoid data races. http://blog.regehr.org/archives/490

Rust can't prevent one from doing all the right low-level synchronisation in the wrong order. In fact, I don't think any language can, without somehow being able to understand the spec of a program: something that's a race condition in one case, may not be a race condition elsewhere (this differs to a data race, which isn't context dependent).


Rust does not prevent all race conditions because doing so would be impossible. It would be akin to solving the halting problem.

Deadlocks, and other synchronization issues are just some 'general race conditions' Rust can't solve.

Rust's prevents 'data races' defined as:

-two or more threads concurrently accessing a location of memory

-one of them is a write

-one of them is unsynchronized

https://doc.rust-lang.org/nomicon/races.html


I recently (past few years) invested in learning Clojure, enough to get some practical things deployed, but I am far from being a Clojure advanced developer. I wanted to learn a Lisp dialect and am glad I chose Clojure. Rich Hickey is a guru. I don't have any gripes with Clojure but I'm not too deeply invested. Several years ago I was also enamored with Julia, which I was investigating for CPU intensive programs, but never had the time to commit and I was concerned about Julia being too youthful and possibly not getting enough traction. Should I learn D for CPU intensive programs? Also, with Clojure I can make use of the many Java libraries for I/O due to Clojure's good Java interop. Does D have the analogous benefit of tried and tested I/O libraries? Thanks for any suggestions, D has my intrigued.


Is the GC mandatory in D? I was under the impression some time ago that D could run GC-free, but the standard library still widely used GC. Did I just misunderstand?


In my understanding, you're overall correct, but they've also been working on reducing that need, making more and more of it work without a GC.


Currently working on making the Exception handling system usable without the GC. Expect it soon.


Great! (and, congrats on the re-licensing.)


You can tag a block @nogc, if you just need to avoid it for a specific part of your program. This can be done with the whole program, but quite a lot of the standard library requires the GC. I should point out that the GC has no problems that affect day to day usage, the stuff people complain about is when it's running for a while (it's conservative atm so it leaks).


If you can tag the entire program @nogc, great.


You can go easier on the GC or avoid it altogether. See this article and the discussion:

https://news.ycombinator.com/item?id=13914308




Join us for AI Startup School this June 16-17 in San Francisco!

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

Search: