edicateD

D FAQ

Please note: this is not an official FAQ! This is my own collection of questions, typically asked by the newcomers in D newsgroup. Most answers rely on the information Walter gave in the newsgroup, private talks, and D specification, but some are my own investigations. As the result, this FAQ might not be completely relevant to the latest version of D, although I do my best to track all the changes and update the FAQ accordingly.


Where can I get D? What versions exist?
Right now the only D implementation is Digital Mars D (DMD) alpha compiler for Windows. However, a multi-platform D compiler translating D code to C is planned, codename Dfront. It should work on any platform that has an ANSI-compliant C compiler. Work on it shall begin as soon as the DMD reaches final version.

Will D ever be open source?
You can get the source to the DMD compiler front-end in standard distribution - see the src\dmd subdirectory of directory where you've installed the compiler. There are no plans to release back-end sources as of yet. However, Dfront is going to be completely open-sourced for sure. Note, this is concerning the compiler only, the library source is opened, so is the garbage collector.

How is D different from Java?
They are two absolutely different languages, most things they have in common came from their ancestor, C++. Java goals are simplicity, and thus it is entirely built around the concept of class, and platform-independency - so it is compiled to bytecode and interpreted by a VM. D, while being simpler than C++, and allowing to write platform-independent code, provides easy ways to do low-level work: pointers, interfacing to native APIs, inline assembler. It has no VM, programs are machine-code binaries native to one platform (although nothing stops you from writing a D bytecode compiler and VM).

How is D different from C#?
C# is Microsoft's reply to Java, and those languages have much in common. D is a separate, independent development, covering different areas than C#, and is not a Java competitor. While there are some common features in these two languages, like garbage-collected environment, the difference between them is much bigger.

Why D uses garbage collection? Isn't it slow?
Not really. Modern garbage collectors do a cycle rather fast. In fact, garbage collected program might even run faster than the one using traditional techniques: in typical C program, you always free memory after use, while in D, it'd be freed only if system is low on resources, otherwise not wasting time on cleanup at all, and letting program run at full speed. Garbage collectors also do heap compacting, resulting in more cache hits and less swapping. And in those rare cases when time is critical, and you must be absolutely sure that GC won't run the collecting cycle at some point, you have full control over it to enable or disable it when necessary. On other hand, garbage collection introduces many advantages. For example, it is absolutely legal for D function to allocate an array and return pointer to it, something not likely to be seen in C++. You don't have to release memory in destructors, and need for them is thus greatly reduced. As the result, size of compiled large programs tends to be smaller. So, in general, garbage collection is a modern technique that greatly simplifies software development and makes it less error-prone, giving benefits much more valuable than disadvatages it has.

Why is there no operator overloading in D?
At first, it was a design decision. Arguments against operator overloading are that it is mostly used for strings, complex numbers, and smart pointers, and all these are built-in into the language. However, the latest discussion on the topic in the newsgroup has discovered great interest of this feature in most potential D users, so it is likely to be seen in further versions of D. It's not in the official specification, though, nor is in the latest D version. We have to live without it for now.

What about templates?
Originally, templates weren't planned in D. However, being a fundamental stone of generic programming, they seem to be too powerful feature to be dropped. We will most likely not see them in D 1.0, but further versions may introduce templates to the language. There is no concrete information concerning syntax and usage of templates as of yet.

Why doesn't D provide a better alternative to printf?
The reason is simply that there is no typesafe mechanism to pass variable number of argument to D function, and no overloading to implement C++-style streams. This will most likely change in near future, and D 1.0 will provide some safe way to output data to screen. For now, the only way is to use printf.


Copyright © 2002 Pavel "EvilOne" Minayev (evilone@omen.ru)
This site is best viewed with Microsoft Internet Explorer 6 or higher in 1024x768 display resolution