Porting From D1
Difference (last change) (no other diffs, normal page display)
Changed: 3c3
On important point, if you don't instantiate your template, the compiler will not tell you if the template compiles or not (only syntactic checks are done). |
An important point: if you don't instantiate your template, the compiler will not tell you if the template compiles or not (only syntactic checks are done). |
This is going to start as a quick notes page, and may never evolve into a well formed page. These notes will be from a port of Juno and anything that comes to mind while writing it. This is also written for Phobos -> Phobos and will not provide advice about where to get Tango library features.
An important point: if you don't instantiate your template, the compiler will not tell you if the template compiles or not (only syntactic checks are done).
See also D 2.0 Specific Features.
Immutable
One of the major changes in D is how const works. Const is transitive and is intended to support immutable. And with that change the string alias was updated to
|
This means you can modify the array, but not its contents. In the case that you are modifying the content you'll want to change string to char[]. In other situations you'll need to make different choices depending on what you are doing.
Two commits related to this are Return immutables and constants and Update function signatures.
Functions should take a const, or in as this allows the function to take mutable and immutable data. Unless the parameter is going to be change. But returning from a function you'll want to go with immutable if at all possible, usually if returning a char[].
Also be aware of .idup for arrays, std.exception.assumeUnique. For calling C functions, std.string.toStringz.
core module
The runtime has been split out from Phobos this means some things will be found in core instead of std. For example std.gc has moved to core.memory.GC as seen on this commit.
New line literal
Use of \n outside of quotes is no longer valid, use "\n".
Structs
The this reference is now a value type inside structs, be sure to remove any dereferences *this -> this and add references this -> &this
Operator Overloading
Operators no longer have their own overload function named after them. Instead there are functions for "types" of overloading, such as opBinary/opUnary. This is one area where it is simpler not to forward to your existing functions and write it with the new system in mind. I won't go into details, but leave you with this commit.
Function Name changes
Phobos has changed some function names to be consistent with a standard, for example tolower() is now toLower(). I won't give a full list but here is some off the top of my head.
- tolower
- toupper
- isdir
|
And others got templatized:
|
Note that templates when passed a single parameter, parentheses are not required.
Library Semantic changes
With the introduction of ranges there are changes to how some functions operate.
std.string.find has been replaced by std.algorithm.find and does not return an index, instead it will return the range advanced to that location. If you wish to see if you found an element check
|
Catching more things
The compiler now finds more problems or potential problems in code.
|
Control flow is required in switch statements.
There are others just can't remember them.