This is the homepage of Peter Alexander.
I write code.
I make games.
Recent Posts
Scoped Imports in DAPI Performance
Simplicity in Everything
Homepage 2.0
Links
github.com/Poita@Poita_
Google+
Atom Feed
Scoped Imports in D
Posted: 26 Jan 2012 - Link
One of the nice things about the D programming language is that it has very convenient syntax for conditional compilation. For example, suppose you want to print out some useful info in debug builds. You just use:
debug writeln("Value of x is ", x);
One problem that I constantly run into in cases like this is that I haven’t imported std.stdio, so I have to go right up to the top of the file, add debug import std.stdio;, back down again, and continue. Sigh.
Not so fast! D has scoped imports, so you can put the import
std.stdio; right where you need it.
void main(string[] args)
{
debug import std.stdio;
debug writeln(args);
// ...
}
It’s the little things like this that make D so pleasant to use.