This Week in D October 2, 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 2.072.0-b1 came out this week, the beta of the next major release (as opposed to last week, which was a bug fix release). This has some new features, including dub included in the package, extensions to std.experimental.ndslice, and a few deprecations to clean up legacy cruft in the language and open the door for new features.

A notable deprecation is using the result of a comma operator now triggers a deprecation warning. The compiler devs are hoping to weed out uses of that old C operator in order to open the possibility of adding a tuple unpacking syntax to the core language. I'd speculate that might happen in about a year.

In the community

Community announcements

See more at the announce forum.

Tip of the Week

This week's tip is an old one, about member function pointers, by Walter Bright.

The tip is here: Member Function Pointers in D, and summarized, it suggests:

class C {
  int a;
  int foo(int i) { return i + a; }

auto mfp = function(C self, int i) { return; };
auto c = new C();
mfp(c, 1);

Yes, using a function pointer that takes an explicit this (or self since this is a keyword) argument that simply forwards the call. This simple code is pretty easy to write and works equally well to the C++ option.

A few notes: using the function keyword ensures you don't accidentally reference a local variable, which would change the type to delegate and possibly allocate memory for a closure.

There are other ways to do member function pointers in D, including taking a delegate directly off the class and poking its ptr member, or casting it to a function that takes the hidden argument explicitly, but those ways are less reliably safe to do than the simple wrapper Walter describes.

Walter's pattern is a good arrow in your D quiver.

Learn more about D

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