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.
It hasn't been a full week since the last edition because it was late. From here on, we'll be shooting for a weekend write-up each week.
This Week in D is in the process of being hosted at dlang.org. Starting soon, you'll be able to find this publication there.
Walter Bright will be presenting at NWCPP on Jan 21 at Microsoft!
D: What's Cooking in 2015 by Andrei Alexandrescu on Thursday, January 22
Berlin Meetup: Friday the 23rd of January from 17:00 to 19:30 at the Melbourne Cantee
Chuck Allison to deliver keynote
Call for Submissions is still open!
DConf 2015 discounted hotel rooms now available
Thanks to p0nce for a nicer DConf logo!
Hope to see you there!
See more at digitalmars.D.announce.
Since the last issue of This Week in D, the forum has been dominated by discussions on website and associated process improvements.
However, that wasn't everything - there were also discussions on new DIPs (D Improvement Proposals), targeting game consoles, and other items.
See more at forum.dlang.org and keep up with community blogs at Planet D.
In March 2014, Cybershadow wrote a post about Functional Image Processing in D. This post demonstrates how to use D's templates and other features to make efficient and elegant code for working with images of various color layouts.
I wrote about HTML parsing on Stack Overflow again this week, demonstrating how to use my dom.d library to do web scraping.
The D Idioms List got new entries:
This week, we'll look at UFCS, Uniform Function Call Syntax to write extension methods to types and help improve encapsulation.
D, when encountering obj.func(args...), will first attempt a member lookup. Member lookup includes direct methods, inherited methods, alias this members, and opDispatch, and opDot rewriting. If none of those succeed, the compiler will attempt to rewrite the expression into func(obj, args...) and compile that.
void foo() { void bar(Object obj) { } obj.bar(); // won't work because bar is a local symbol }To use a function with UFCS, it must be defined at module scope:
void bar(Object obj) {} void foo() { obj.bar(); // will work }
If the rewrite succeeds unambiguously, the code will compile. Any type may be extended in this fashion:
float divideBy(float divisor, float dividend) { return divisor / dividend; } void main() { float a = 5.divideBy(2); // works on built-in types too! // rewrites into a = divideBy(5, 2); assert(a == 2.5); }
UFCS is used in D for three main reasons:
import std.algorithm; void main() { [1,2,3] .filter!(isOdd) .map!((a) => a**2) .writeln; }None of the functions there are members of the object, but thanks to UFCS, that will compile.
module foo.bar; package int a; module foo.baz; import foo.bar; // int a IS accessible module something.else; import foo.bar; // int a is not accessible
Find more D tips at the D idioms list or buy my D Cookbook for a more in-depth examination of many D tricks.
If you'd like to submit a tip, email me.
To learn more about D and what's happening in D: