156 points · by Halienja · 10y ago · 78 comments
We nailed it with arrays (Jan Knepper’s idea), the
basic template design, compile-time function execution
(CTFE)
One of my favourite things about D is that it has a full compile-time D interpreter. You can do "template metaprogramming", so to speak, in the same language as D itself (it's probably a bit more fair to compare it to how lisp macros are "compile-time").It's a bit sad that Rust is getting all of the attention in the spotlight, because D is a great, modern, safe language. If you've only heard about D 15 years ago and never tried it again, give it another look. The current D is really a new language, which was briefly called "D2" for a while.
Now, if Symantec could just fix the stupid licence of the reference compiler...
https://forum.dlang.org/thread/lodjbuvdhimrvrdngldy@forum.dl...
This isn't a zero-sum game! D is a fine language.
Actually you can do this on CTFE on D, doing an import of a file and dumping it to an enum. The only big pitfall of this, is that enforces to read the whole file by the compiler.
> Compile time IO doesn't make much sense either.
While I agree with D's decision here, there are other languages which do allow anything at compile time. See Jai, for example.It's very nice, but it isn't memory safe.
Probably the biggest memory safety issue is buffer overflows, and D does a good job stopping that (array overflow checking).
Context: safe Rust is also a subset of unsafe Rust. But when people mention a language without qualifiers, they mean whatever the default is. D (appears) to default to a non-memory safe language, and Rust defaults to a memory-safe one. I believe this is what OP meant. (this also ignores the relative feature sets of the various sub/super-sets)
import std.c.stdio;
int main() {
int x = 7;
int* p = &x;
printf ("%d\n", *(p + 1));
return 0;
}
This compiles in D and violates memory safety.If you prefer a documentation answer(https://dlang.org/spec/arrays.html#pointers) These are simple pointers to data, analogous to C pointers. Pointers are provided for interfacing with C and for specialized systems work. There is no length associated with it, and so there is no way for the compiler or runtime to do bounds checking, etc., on it.
It seems like a very solid language. You can write low level C like code if you really want to, but it defaults to safer, higher level code without losing much efficiency.
I'm going to try it out with some bigger projects. I have some issues. Windows support seems a little flakey but it's ertainly usable (the default dmd compiler works very well on windows but the code it makes isn't the best it could be, and ldc makes much higher quality code, but isn't quite stable on windows. (Although it's certainly looking good enough to use).
I think it's well worth a look. I like it a great deal more than Rust
What kind of question is that? Anders Hejlsberg was what, 39 when he started working on C# and 52 with Typescript? It's the same as with screenplays. You start writing when you have experience.
But sure, I would agree that having a natively implemented variant type would be better, even if this one can serve many of the same purposes.
Class = reference type, supports polymorphism, inheritance
Struct = value type, does not support polymorphism, inheritance
The variant type based on a struct is implemented through the language's metaprogramming facilities.
ironically, i haven't really used D for the same reason i haven't really used rust - i've yet to have a project for which ocaml wasn't a better choice. (i know both D and rust address things ocaml doesn't, but they aren't the things i tend to need for my personal projects.)
You can get some very elegant and efficient code with D, while OOP tends to have more runtime overhead.
That doesn't mean there's no downside to the metaprogramming in terms of project complexity, but once you get past the part where you rebuild the universe from scratch it's smooth sailing.
Video: C++, Rust, D and Go: Panel at LangNext '14:
http://jugad2.blogspot.in/2016/08/video-c-rust-d-and-go-pane...
Key team members or inventors of those languages, speak.
This is slowly changing, of course, the farther we get away from 1.0. I still worry about it, though.
[1] https://www.reddit.com/r/programming/comments/2g03af/ds_garb...
http://forum.dlang.org/post/jcfwcdvvfytdkjrpdeld@forum.dlang...
I wish this mindset was more prevalent in open source. I find that the best (most well-designed and useful) projects are those that don't concern themselves with marketing.