I admire Walter Bright and the D language & community. I think the project sets a great example, and parts of Zig were inspired by or at least informed by the D language. That said, in the spirit of friendly competition, here’s one difference: how lean binaries are:
$ zig build-exe hello.zig --release-small --strip --single-threaded
$ strip ./hello
$ ./hello
Hello, World!
$ ls -ahl ./hello
-rwxr-xr-x 1 andy users 6.0K Jul 3 19:18 ./hello
$ ldd ./hello
not a dynamic executable
The richness and flexibility of compile-time features almost make it feel like a lisp, with the slight downgrade of sometimes working on strings of source code instead of sexps. Regardless, like the article says, D’s metaprogramming alone is worth the entry price of reading a few books or tutorials about the language.
The richness and flexibility of compile-time features almost make it feel like a lisp, with the slight downgrade of sometimes working on strings of source code instead of sexps
Id like to see a feature comparison of D and Zig.
I admire Walter Bright and the D language & community. I think the project sets a great example, and parts of Zig were inspired by or at least informed by the D language. That said, in the spirit of friendly competition, here’s one difference: how lean binaries are:
vs
I’m sure there are plenty of things D could show off in this thread. And please let me know if there are other flags I could pass above.
Using your example, I used D’s betterC mode
https://dlang.org/spec/betterc.html
dmd -betterC hello_betterc.d
Getting 8.2K executable.
rwxr-xr-x 1 v v 8.2K Jul 4 01:46 hello_betterc
/d-vs-world/binsize$ ./hello_betterc Hello betterC
/d-vs-world/binsize$ ldd hello_betterc
–
–
dmd –version
DMD64 D Compiler v2.086.1-beta.1
(sorry, had to make several formatting updates to the post)
Ah! Thank you for sharing this. I tried to use
-betterC
but I didn’t know how to get past the compile errors from my hello world code:which gave:
I see now that the trick was to use
core.stdc.stdio.printf
.I have only read about Zig but they feel very different too me on a high level.
Zig wants to be a simple language: Few features that can be combined in powerful ways.
D wants to be a comprehensive language: Many features so wherever you go you have the right tool for the job.
D has been a real pleasure for me. I did the 2017 AoC in it.
The richness and flexibility of compile-time features almost make it feel like a lisp, with the slight downgrade of sometimes working on strings of source code instead of sexps. Regardless, like the article says, D’s metaprogramming alone is worth the entry price of reading a few books or tutorials about the language.
What do you mean working on strings?
I’ve just been reading the tour, prompted by this article. I believe it’s to do with mixins and other compile-time function stuff.
Yes, string mixins. It’s kind of a compile-time eval but with some restrictions to prevent certain kinds of abuse of other evals in other languages.
But that’s just one tool, there’s lots of other ways to metaprogram in D that don’t require building strings of code yourself.
nope