Last update March 31, 2012

Porting From D1

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.


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

alias immutable(char)[]

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".


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
Also some things may have been moved into a struct, for example

std.base64.encode -> std.base64.Base64.encode

And others got templatized:

toUshort() -> to!ushort()

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

!std.algorithm.find(range, item).empty

Catching more things

The compiler now finds more problems or potential problems in code.

do { } while; // Requires semicolon

Control flow is required in switch statements.

There are others just can't remember them.


See Introduction to std.datetime.

FrontPage | News | TestPage | MessageBoard | Search | Contributors | Folders | Index | Help | Preferences | Edit

Edit text of this page (date of last change: March 31, 2012 22:33 (diff))