Live data from Hacker News

D Programming Language

dlang.org

181–190 of 278 posts

Re: D Programming Language

#181

IMHO D just missed the mark with the GC in core. It was released in a time where a replacement for C++ was sorely needed, and it tried to position itself as that (obvious from the name). But by including the GC/runtime it went into a category with C# and Java which are much better options if you're fine with shipping a runtime and GC. Eventually Go showed up to crowd out this space even further. Meanwhile in the C/C+…

My (likely unfair) impression of D is that it feels a bit rudderless: It is trying to be too many things to too many people, and as a consequence it doesn't really stand out compared to the languages that commit to a paradigm. Do you want GC? Great! Do not want GC? Well, you can turn it off, and lose access to most things. Do you want a borrow-checker? Great, D does that as well, though less wholeheartedly than Rust.…

> and lose access to most things

What "most things" are these?

Re: D Programming Language

#182
post #171

Earlier quoted context omitted.

But then, to use D for performance, would I then have to master both D, C and their interaction? That doesn't seem great. It's like having to learn 2 languages and also how they interact.

No, you can just write D. It'll have the same performance as C, if you write C-like code. It might have better performance than C if you use templates (just like in C++).

But why then did arcadia_leak imply as far as I understood him that C is needed for performance in D?

But D is not included in the benchmarks game at debian.net, which isn't fair to D either as far as I can tell.

Re: D Programming Language

#183
post #119
post #34

Earlier quoted context omitted.

This is a somewhat simplistic view of ownership and borrowing for modern programming languages. Pointers are not the only 'pointer's to resources. You can have handles specific to your codebase or system, you can have indices to objects in some flat array that the rest of your codebase uses, even temporary file names. An object oriented (or 'multi paradigm') language has to account for these and not just literal poin…

How does Rust (or C++) treat array indices as resources? And won't that defy the reason to use indices over pointers?

Here's how it works in some C++ libraries.

  struct resource {
    resource(ctx *c, ...) {index = c->store(...); ...;}
    size_t index;
    ctx *c;
    ~resource() {c->free(index);}
    // copy constructor+op creates new handle
    // move constructor+op copies the handle, maybe zeroes the current one 
  };
With this you can rely on RAII, smart pointers, upcoming lifetime checks and annotations, etc. The core idea is that you treat objects of classes like this as values and everything works out seamlessly. Even if they are 'pointers' in all but name. You can also overload the dereference operator for it to have pointer-like syntax, but that is discouraged.

When you have just once resource this might be overkill but for large projects with tangled webs of resources, this sort of setup really makes the code simpler and easier to design.

That's C++ for you, simple things look complex but once you get into big hairy projects things stay at the same level of complexity instead of becoming an unmanageable mess.

D almost supports RAII, and the compiler seems to do some automated copy to move conversion, but this is the sort of thing that really, really needs a large number of users and compiler implementers to iron out issues and corner cases. Nothing against D, the language is pretty neat!

Re: D Programming Language

#184
post #182

Earlier quoted context omitted.

No, you can just write D. It'll have the same performance as C, if you write C-like code. It might have better performance than C if you use templates (just like in C++).

But why then did arcadia_leak imply as far as I understood him that C is needed for performance in D? But D is not included in the benchmarks game at debian.net, which isn't fair to D either as far as I can tell.

Not necessarily, you can just call the functions in the C library from D as you'd call them from C or C++ with the added benefit of being able to leverage the D GC, RAII, macros etc.

https://dlang.org/spec/interfaceToC.html

Dunno about the Debian benchmarks game or their build environment. I did my own benchmarks and it was quite easy to write working D code compared to C, C++ or Rust. I used LDC, the LLVM D compliler as opposed to DMD. Dub is not that seamless compared to Cargo but given that you have to set things up manually, it doesn't encourage dependency hell.

If you're writing networking code, Go is probably a better choice than vibe.d.

Re: D Programming Language

#185
post #182

Earlier quoted context omitted.

No, you can just write D. It'll have the same performance as C, if you write C-like code. It might have better performance than C if you use templates (just like in C++).

But why then did arcadia_leak imply as far as I understood him that C is needed for performance in D? But D is not included in the benchmarks game at debian.net, which isn't fair to D either as far as I can tell.

You can use C but you are not forced to. In fact, you can write C and convert it automatically to D (though it will need some amount of manual editing afterwards). C is supported as a syntax option but it's still the same compiler for both under the hood. As rightly pointed out by the user above, you can write the same high performance code in the D syntax. The reverse is not true, though -- using high level concepts like classes and GC allocation is not supported in the C syntax.

Re: D Programming Language

#186

Earlier quoted context omitted.

One good case for it that I see is a viable basis for cross-platform desktop apps. Today, cross-platform desktop GUI apps are either just a snapshot of the website contained inside Electron, or a C/C++ code base with manual memory management. D can serve as a nice middle ground in that space.

Flutter does cross platform + web and is as close to native as you'll get without writing code directly in Swift, C#, etc. You're free to start a company and solve a real business problem. If I became a D expert tomorrow it's not going to make me more money. It's not getting me a better job.

Why yes, D is not the best choice if you're looking for instant profit.

Re: D Programming Language

#187
post #178

Earlier quoted context omitted.

dplug is a framework for building audio plugins that do realtime signal processing, and its creator has produced several well-sold plugins under the "Auburn Sounds" studio name. https://github.com/AuburnSounds/Dplug

Interesting. That might fit the bill, though I am not completely sure. Do you happen to know why D has not been accepted into the benchmarks games at debian.net? I heard that D developers contributed D code, but that D was never accepted.

Like 20 years ago:

https://web.archive.org/web/20060525101747/http://shootout.a...

Because:

https://benchmarksgame-team.pages.debian.net/benchmarksgame/...

Re: D Programming Language

#188
post #99

Earlier quoted context omitted.

Can you explain what BetterC is, and what it is used for? I think there's also something called ImportC. Not sure what that is either. I read the D blog sometimes, and have written some programs in D, but am not quite clear about these two terms.

https://dlang.org/spec/betterc.html https://dlang.org/spec/importc.html > Note: ImportC and BetterC are very different. ImportC is an actual C compiler. BetterC is a subset of D that relies only on the existence of the C Standard library. BetterC code can be linked with ImportC code, too. D contains an actual C compiler because Walter Bright wrote one long ago and then incorporated it into D. Zig also contains an act…

thanks.

Re: D Programming Language

#189

Earlier quoted context omitted.

My (likely unfair) impression of D is that it feels a bit rudderless: It is trying to be too many things to too many people, and as a consequence it doesn't really stand out compared to the languages that commit to a paradigm. Do you want GC? Great! Do not want GC? Well, you can turn it off, and lose access to most things. Do you want a borrow-checker? Great, D does that as well, though less wholeheartedly than Rust.…

> and lose access to most things What "most things" are these?

Noteably for me at least is the 'new' keyword and resizing arrays with the length property.

https://dlang.org/spec/function.html#nogc-functions

Re: D Programming Language

#190

Years ago I got interested in D. It's a great language, but at the time its garbage collector was leaky. There weren't any D entries on the Benchmarks Game back then, so I ported most of the programs to D and optimized them as best I could as a newcomer. Performance wise, D was in the C/Rust/C++ range and in many cases it even beat Rust and C++. I tried to get the community involved to help the language gain wider ad…

> weren't any D entries

fwiw nbody.dlang 2005

https://salsa.debian.org/benchmarksgame-team/archive-alioth-...

Like 20 years ago:

https://web.archive.org/web/20060525101747/http://shootout.a...

Post reply on HN