Live data from Hacker News

The reference D compiler is now open source

forum.dlang.org

201–210 of 313 posts

Re: The reference D compiler is now open source

#201
post #147

Good to hear the news, and congrats to all involved. Since I see some comments in this thread, asking what D can be used for, or why people should use D, I'm putting below, an Ask HN thread that I had started some months ago. It got some interesting replies: Ask HN: What are you using D (language) for? https://news.ycombinator.com/item?id=12193828

Too late to the party to add my answer to your AskHN, but here we go: I use D at Netflix for machine learning backend.

Interesting, thanks!

Re: The reference D compiler is now open source

#202

Earlier quoted context omitted.

> 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).

Re: The reference D compiler is now open source

#203

Earlier quoted context omitted.

The GC is only relevant if you allocate using the GC, because that is the only time the GC can run. If you use @nogc on your functions, you are guaranteed not to have GC allocations. You can use D as a better C with no GC but other good features. You can even avoid the D runtime compeletely if you want.

Thanks for your helpful answer. ...and I don't understand why some people have downvoted my question. Anyway, I'll continue reading the docs :)

Didn't downvote, but found "Please don't get me wrong, as I don't want to start a flame here, but…" redundant and slightly annoying. ;)

Re: The reference D compiler is now open source

#204
post #162
post #59

Please don't get me wrong, as I don't want to start a flame here, but why do they call D a "systems programming language" when it uses a GC? Or is it optional? I'm just reading through the docs. They do have a command line option to disable the GC but anyway...this GC thing is, imho, a no-go when it comes to systems programming. It reminds me of Go that started as a "systems programming language" too but later switch…

D's garbage collector is both written in D and entirely optional, that alone should qualify it as a systems language. The gc can be disabled with @nogc, the command line flags are only if you want to disable it for the whole program or if you want warnings as to where the allocations happen. https://godbolt.org/g/IQ0O06

[deleted]

Re: The reference D compiler is now open source

#205
post #186

Earlier quoted context omitted.

Go does allocate and free at runtime, it just isn't explicit because its a garbage collected language and the garbage collector handles most of the freeing for you. Different GC'd languages handle allocations differently, some have a keyword, some do it whenever creating an instance of a type over a certain size. With C, C++ and Rust allocating memory often boils down to calling something equivalent to malloc and fre…

Does modern C++ or rust allow you to say "deallocate this pointer here " (like free or delete)? I was under the impression that Rust (and safe_ptr) deallocate at scope end, which could also cause framerate issues (unless you do ugly scope hacks). I do agree that you're unlikely to bump into this issue, though.

[deleted]

Re: The reference D compiler is now open source

#206

Earlier quoted context omitted.

uniq_ptr in C++ and Box in Rust are both considered smart pointers, dealing with memory management, and don't do any reference counting, bounds checking, or anything else like that at runtime. They're a compile-time abstraction only.

This is not really accurate. A unique_ptr move assignment must check the target location to see if it's null, and if not, free the underlying object. It also has to clear the source location. This is more than just a compile-time abstraction compared to raw pointers, even if modern compilers can elide the code most of the time. Also, the lack of checking leads to unique_ptr dereferences potentially having undefined b…

I think you're picking nits. The equivalent raw pointer code would also have to free a pointer it was overwriting, so I'm not sure that's so interesting (definitely not in terms of "zero cost abstractions").

That said, the null checks required for C++'s destructor semantics are definitely a little more interesting in this respect, given one is rarely going to do this with raw pointers (although the cases when you don't need to do it also seem like cases the optimiser can handle fairly easily), but an extra branch and/or write at least seems significantly qualitatively different to the full reference counting that people often think of when talking about "smart pointers", which is the point the parent is trying to make (smart pointers aren't just reference counting).

Re: The reference D compiler is now open source

#207

Earlier quoted context omitted.

I think a lot of languages that get popular have to have a thing. Like a thing they do well, and hopefully change the world a little... Python had math and has lots more maths now. R also has math and started to kill Python, but now Python has Tensorflow and PyTorch. Scala has Spark. Java has Tomcat, and everything that followed, which is probably 20% of the world's mass by volume. Go has Docker Ruby has/had a railro…

> Does D have a thing? Probably its most useful feature is rather subtle. It's very easy to express diverse ideas in code in D without having to resort to contortions. It's something people realize after having worked with D for a while. It is not the result of having feature X (you can always find feature X in other languages or a way to make X work), it's the combination of various X's. For example, some algorithms…

I really like how purity in D is so... practical. I like that a for loop is totally allowed in pure code as long as it modifies no data outside the pure block. One of the most annoying things in Haskell was to translate some algorithm that looks very natural in a for loop into some other sort of combination of map or reduce or something even more complicated.

(Yes, I know Haskell can also fake for loops more cleanly with monads, but they still feel awkward and unnatural.)

Re: The reference D compiler is now open source

#208

Earlier quoted context omitted.

> (or a very small one, by default). Some details here... every language other than assembly languages has some amount of runtime. This is Rust's: https://github.com/rust-lang/rust/blob/master/src/libstd/rt.... (as you allude to, many people refer to this amount of runtime as "no runtime" since it's very, very small.) You could also consider some other things as part of a runtime; for example, by default on most plat…

> every language other than assembly languages has some amount of runtime How are you defining "runtime" such that this statement is correct?

What language are you thinking of that I'm missing? C has crt.0, for example.

Re: The reference D compiler is now open source

#209

Earlier quoted context omitted.

uniq_ptr in C++ and Box in Rust are both considered smart pointers, dealing with memory management, and don't do any reference counting, bounds checking, or anything else like that at runtime. They're a compile-time abstraction only.

This is not really accurate. A unique_ptr move assignment must check the target location to see if it's null, and if not, free the underlying object. It also has to clear the source location. This is more than just a compile-time abstraction compared to raw pointers, even if modern compilers can elide the code most of the time. Also, the lack of checking leads to unique_ptr dereferences potentially having undefined b…

Ah! That makes perfect sense, thank you. I guess it's just Box, then :p (This is the difference in move semantics between C++ and Rust showing.)

I think my original point still stands here though: smart pointers != refcounting, inherently.

Re: The reference D compiler is now open source

#210
post #206

Earlier quoted context omitted.

This is not really accurate. A unique_ptr move assignment must check the target location to see if it's null, and if not, free the underlying object. It also has to clear the source location. This is more than just a compile-time abstraction compared to raw pointers, even if modern compilers can elide the code most of the time. Also, the lack of checking leads to unique_ptr dereferences potentially having undefined b…

I think you're picking nits. The equivalent raw pointer code would also have to free a pointer it was overwriting, so I'm not sure that's so interesting (definitely not in terms of "zero cost abstractions"). That said, the null checks required for C++'s destructor semantics are definitely a little more interesting in this respect, given one is rarely going to do this with raw pointers (although the cases when you don…

I'm not picking nits. This is not just about the freeing (which I assume will happen in the minority of cases), but also the test-and-branch code generated (plus the zeroing of the source location), which is something that you can't just ignore even if branch prediction is perfect. The claim that they are a "compile-time abstraction only" is pretty absolute.

Also, the cost of it not being memory-safe should not be ignored.

Post reply on HN