
Metaprogramming is less fun in D - ingve
https://epi.github.io/2017/03/18/less_fun.html
======
loeg
It's a good article. The title is slightly bait-ey in that 'less fun' is a
good thing in this context. C++ metaprogramming, at least for this example,
requires a bunch of boilerplate. The D equivalent is built with standard
language features and produces understandable error messages when mistakes are
made.

It's a nice little anecdote about why you might want to use D in place of C++.

------
echelon
Does D have much of a use case left?

Java and C# are statically typed, garbage collected languages with a huge
adoption and massive amounts of tooling.

D's attempt to become an alternative to C and C++ was eclipsed by Rust, which
doesn't have the GC overhead and has a ton of other really compelling
features.

There are a bunch of other new and exciting languages too: Go, Nim, ...

Why would anyone choose D today? (Serious question.)

~~~
shakna
I wrote my thesis in D.

I considered C/++, Rust, Go, Nim and D.

D won because:

* Less manual memory management

* Awesome compile-time errors (this is absolutely key)

* Super easy tooling setup

* High-level abstractions in stdlib

* Still reasonably fast

* AOT compiled, which was a hard requirement for what I was researching

~~~
kazinator
> _I wrote my thesis in D._

Really? So like your abstract goes in the main function, or how does that
work? Do you use reference types for citations or just external symbols?

Good choice of language; though, who wants a "Ph. C++" or "Ph. Rust" affixed
to their name, know what I mean?

~~~
WalterBright
> Really? So like your abstract goes in the main function, or how does that
> work? Do you use reference types for citations or just external symbols?

D has a documentation generator (Ddoc) as part of the language. It turned out
to be useful as a standalone documentation generator. The dlang.org website is
built using Ddoc, and I've even published a couple books in Ddoc. It feels a
bit weird running a compiler over your marked up text, but that feeling passes
after a while :-)

~~~
systems
can D be used as drop in replacement for c++ in something like metatrader

i think, it might be worth it if you guy investigate areas like these, many
trading platforms have interfaced to c/c++ if D and be added as a drop in
replacement, with some more safety guarantees, you have a big niche market
here that D can survive on for a long time

~~~
petre
D interfaces very well with C/C++ code and libraries. It was designed to do
that from the begining. Some D libs are actually bindings to C/C++ libraries.
You don't need to replace existing C++ code/libraries, you can just integrate
them in a D project.

------
amelius
Since the article uses an event system as an example, I'm wondering: how well
do closures work in D? (Closures are very convenient when dealing with
events).

~~~
Ace17
They work fine. Everything is captured by reference, and is ultimately garbage
collected. Unlike C++, you're not required to use a special "local function"
syntax.

~~~
amelius
Interesting. Is this all guaranteed to work also in a multithreaded
environment?

How efficient is the garbage collector, and are there pauses?

~~~
p0nce
> Is this all guaranteed to work also in a multithreaded environment?

Yes.

> How efficient is the garbage collector, and are there pauses?

Not very efficient, and there might be pauses if you are not careful. Now if
your closure doesn't escape (just a local function + context) it won't use the
GC. So you can use delegates in @nogc code.

------
eximius
I'm surprised someone hasn't chimed in with a Rust version of this by now.

------
mhogomchungu
Its a lot easier to do events based programming in Qt/C++.

Here is a Qt/C++ tasks[1] that greatly simplified async programming using Qt's
event system.

[1]
[https://github.com/mhogomchungu/tasks](https://github.com/mhogomchungu/tasks)

------
Immortalin
What does the []{...} mean in C++? Is it an array of anonymous functions?

~~~
klickverbot
It's a lambda expression ("closure"/"anonymous function"/…) that doesn't
capture any outside state (see e.g.
[http://en.cppreference.com/w/cpp/language/lambda](http://en.cppreference.com/w/cpp/language/lambda)).

------
skdotdan
Many threads on D on HN lately. Is it a trend?

~~~
mnx
Wasn't the reference compiler open-sourced recently? That could've sparked
some new interest.

------
systems
i dont think going after c++ will help d's adoption it didn't work in the past

i dont know what have changed to make it work in the future

i dont remember Go or Rust ever focusing on comparing themselves to another
language as much as d compare itself to c++

d should create its own path same way any other more popular language did

~~~
butterisgood
C++ will always have a leg up over D for me due to the GC stuff. I like not
having GC in C++.

When I want a GC'd C-like I use Go.

D has to find a space between those two for me and a lot of other people.

I don't dislike D. I think D has a LOT of great work done in it. I just really
want all my libraries to be able to be used without GC. And I'm not sure it's
really feasible to have each foot in either world and not just get split down
the middle.

Can someone argue against this worry? It's literally the only thing stopping
me spending more time with D.

Also I've been coding in Ada (lord help me) for fun. Contracts are
interesting.

~~~
penpapersw
An important factor in choosing a language is platform. I'm not going to
choose Go or D to write an iOS app in, because it would be painful and buggy,
if it's even possible in the first place. I'm restricted to Objective-C(++) if
I want it to really be a high quality & native app.

~~~
klickverbot
D can interface with Objective-C just fine. The Apple-provided tooling will
indeed be more convenient for the _developer_ , but the result the end _user_
sees will be a "high quality & native app" just the same.

------
virgil_disgr4ce
I swear this title is generated by a Hacker News NLP bot. Heh :)

