Ruminations on D: An Interview with Walter Bright
dlang.org
dlang.org
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...
> 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.As it turns out (IME) referencing arbitrary data (such as a database schema queried from a 'live' database) is actually of quite limited value.
Where I actually agree that it makes sense is the 'read-a-checked-in-file-and-generate-code-at-compile-time-from-that'. Otherwise, you're mostly just looking at a lot of pain compared to just generating code (that you might check in).
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.
An important difference is that the compiler doesn't know it's using that file ahead of time, which could have some unforeseen consequences, but I don't see anything immediately worrying about that fact since the compiler didn't know about the source either at it's own compile time.
It can be done with:
void[] ctData = import("file.xml");
For example, this feature is used in vibe.d to compile an HTML template language into more optimized code.Considering what we've known about the typical behavior of production programs for decades, why isn't there also an "Initialization Time" in addition to Compile Time and "runtime." (Steady State Time?)
I think it has a bad rap because it's often used to initialize some kind of global state, with all the cons global state brings.
So then what if the language didn't have global state, or only had immutable global state?
It's very nice, but it isn't memory safe.
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)
However, I don't think it is such a big deal, since you can patch it quite well. Mark your main function as @safe and you are force to make everything @safe (or @trusted as a workaround). The type checker will tell you where to look next.
It is interesting that Rust functions are not pure by default. I guess (did not follow the design discussions), because purity is too limiting. D came up with the concept of "weakly pure", which is useful and strong enough. Also you need transitive const to turn a weakly pure into really pure function.
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.
import std.stdio;
@safe int f() {
int* x = new int(6);
delete x; // !!
return *x; // !!!!
}
@safe void main() {
writeln(f());
}Probably the biggest memory safety issue is buffer overflows, and D does a good job stopping that (array overflow checking).
This isn't a zero-sum game! D is a fine language.
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.
The obsolete stuff is dsource.org. Most of it does not compile anymore and has no maintainers. If you are looking for libraries to use, go to https://code.dlang.org/.
Phobos is the standard library. Tango is a D1 projects. Most of it has been ported and integrated into Phobos now. Some people still like the Tango XML library: https://github.com/SiegeLord/Tango-D2
https://semitwist.com/articles/article/view/dispelling-commo...
https://www.reddit.com/r/programming/comments/118y4m/dispell...
[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.