This Week in D January 3, 2016

Welcome to This Week in D! Each week, we'll summarize what's been going on in the D community and write brief advice columns to help you get the most out of the D Programming Language.

The D Programming Language is a general purpose programming language that offers modern convenience, modeling power, and native efficiency with a familiar C-style syntax.

This Week in D has an RSS feed.

This Week in D is edited by Adam D. Ruppe. Contact me with any questions, comments, or contributions.


Major Changes

Beta D 2.070-b1 was released today. It includes a new package std.experimental.ndslice, DWARF-based exception handling on Linux which is a major step toward compatibility with C++ exceptions, and, finally, full Windows headers!

The library change of TypeInfo.init to TypeInfo.initializer is also liable to break some low-level code, so be on the lookout for it if you've written anything on that level.

The git commits this week included a small change to add indication of which test started when running unittests so you can see which one was starting in the event of a crash. This is a small change but should help people track bugs down a little more easily.

The ddoc generator also got improved constraint and overload formatting.

Meanwhile, my unofficial doc generator continued to be developed at a quick pace and is approaching half done. See its current state here.

In the community

Community announcements

See more at the announce forum.

Another D streamer was located this week too: satoshi.

Tip of the Week

A brief tip this week, but one that has eluded a lot of users I've observed: adding seconds to a DateTime or SysTime is as simple as using the + operator:

import std.datetime, std.stdio;
void main() {
    SysTime time = Clock.currTime();
    time += 15.seconds;

    // convert to a DateTime with cast
    DateTime dt = cast(DateTime) time;
    dt += 5.days; // you can still use the + operator

The documentation mentions a function, add, which works for months or years, leading people to think you can ONLY add months or years to these objects. That's not correct.

The reason add is special for years or months is because years and months are of variable length, whereas the other durations aren't (well, usually aren't but std.datetime chose to ignore (yes, the author is very familiar with all the edge cases!) those bizarre cases for simplicity). + 1.months would have to return a special type that is no longer plain arithmetic to account for the different number of days in a month, so it uses a special method instead.

But, for the other cases, you need no special method and can just use the regular addition operator. The durations can be written as number.seconds or as seconds(int).

The convenience names for units smaller than a second are abbreviated. So msecs for milliseconds, while it is seconds for seconds and bigger. Jonathan M. Davis suggests a way to remember it are really small units are small words, and thus abbreviated.

You can learn more by reading this Stack Overflow answer by the author, and this article on the main website.

Learn more about D

To learn more about D and what's happening in D: