You may already have noticed that the D syntax is similar to C syntax so this should be easy to get used to.
D is also just as powerful as C++, it just dropped some really problematic things and added some great new things.
Major additions to C++ include:
- Garbage collection. Don't worry about your objects :)
- Arrays with known length, array slicing, array concatenation
- Class syntax and semantics resemble more the way it's done in Java than C++
- Less (!) pointers. You could say almost no more pointers - but you can still use them if you want to!
- Strings in the language core, strings are NOT zero terminated!
Things that were dropped:
- No more header files. Everything that belongs together should be in one file (ie "module").
- No more preprocessor. You will perhaps miss it at the beginning.
- No forward declarations. (I don't really know if this is 100% true)
- The "->" operator was completely replaced by "."
- Implicit casts - you have to cast explicitly - it's better that way.
Things that were changed and that you have to be aware of:
- You can't define and declare structs and class in just one statement. So you don't need to type a semicolon after struct/class anymore. Example:
struct Foo
{
int x, y;
}
Foo foo;
|
- The constructor and destructor are always called "this" and "~this". The base class' constructor can be called with "super":
class Foo
{
this()
{
super();
}
~this()
{
}
}
|
- Comparing class references to "null" is done with the "is" operator, because the "==" can be overloaded!
|