D and Nim
Ary Borenszweig via Digitalmars-d
digitalmars-d at puremagic.com
Sun Jan 4 13:46:08 PST 2015
On 1/4/15 3:10 PM, Jonathan wrote:
> Hey folks,
>
> I've been recently checking out Nim/rod and feel like it takes a lot of
> inspiration from D (I think the creator was in the D community too as
> some point). How do you think it compares? What areas does D, in
> principle, makes it a better choice? To give you my background, I like
> creating games (mostly using SDL bindings) using new languages, aiming
> for the most efficient yet concise way to write the engine and game logic.
>
> FYI, this is NOT a language war thread. I'm just curious about what
> separates them from a principle level.
In my opinion Nim is superior than D in every aspect (and I say this as
my personal opinion, not to trigger a language war).
There are examples of D code in these two repos:
https://github.com/logicchains/LPATHBench
https://github.com/kostya/benchmarks
Take a look at for example the first one in D and Nim:
https://github.com/logicchains/LPATHBench/blob/master/d.d
https://github.com/logicchains/LPATHBench/blob/master/nim.nim
According to the writeup:
https://github.com/logicchains/LPATHBench/blob/master/writeup.md
Nim is faster than D. And it does so with much less code.
Then look at kostya/benchmarks: D is always behind Nim (except matuml,
where they are similar, but all statically compiled languages are
similar in that one). And Nim's code is always shorter and cleaner. (and
before you reply to this with "but if you add pure nothrow @safe
@abracadabra", continue reading)
There was a time I liked D. But now to make the code fast you have to
annotate things with pure nothrow @safe to make sure the compiler
generates fast code. This leads to code that's uglier and harder to
understand.
Another point is that Nimrod has CTFE but does so with a virtual
machine, so I'm sure it's faster than D in that aspect.
Then, Nim is written in Nim. Having the compiler be written in itself is
a good way to immediately have the developers of the language get the
feeling of the language, find bugs and improve it. Nim has 363 issues
accoring to https://github.com/Araq/Nim/issues . D has 2444 according to
https://issues.dlang.org/buglist.cgi?component=DMD&limit=0&order=bug_status%2Cpriority%2Cassigned_to%2Cbug_id&product=D&query_format=advanced&resolution=---
. Also, because the compiler is written in itself, everything is garbage
collected, so there are no worried when doing CTFE (D's CTFE consumes a
lot of memory, I read in this newsgroup). Nim compiles itself in between
2.5 and 5 seconds.
Also, I get the feeling that D has too many features and not all of them
work in harmony with the rest of them. So people always find small bugs
and others suggest workarounds and eventually people learn to program in
a WDD way (Workaround-development-driven).
Back to LPATHBench, I find things like minimallyInitializedArray and
uninitializedArray, which are great for optimizing things, but it's sad
that one has to use these special functions instead of regular ones
(idiomatic code) to achieve better performance. Also, "uninitialized"
sounds unsafe... And then you must compile your code with -noboundscheck
to get more performance, but that's so unsafe...
But then, both D and Nim have things which I dislike: too many built-in
things. Static arrays, arrays, sequences, etc. Can't these be just
implemented in D/Nim? Why the need for special built-in types with
special operations?
Anyway, just my opinion :-)
More information about the Digitalmars-d
mailing list