An introductory tutorial on templates in D. This post lays the foundation for future articles on more advanced template topics.
Read more...Category: The Language
A Pattern for Head-mutable Structures
Posted onWhen Andrei Alexandrescu introduced ranges to the D programming language, the gap between built-in and user-defined types (UDTs) narrowed, enabling new abstractions and greater composability. Even today, though, UDTs are still second-class citizens in D. One example of this is support for head mutability—the ability to manipulate a reference without changing the referenced value(s). This … Continue reading A Pattern for Head-mutable Structures
Read more...wc in D: 712 Characters Without a Single Branch
Posted onAfter reading “Beating C With 80 Lines Of Haskell: Wc”, which I found on Hacker News, I thought D could do better. So I wrote a wc in D. The Program It consists of one file and has 34 lines and 712 characters. import std.stdio : writefln, File; import std.algorithm : map, fold, splitter; import … Continue reading wc in D: 712 Characters Without a Single Branch
Read more...My Vision of D’s Future
Posted onWhen Andrei Alexandrescu stepped down as deputy leader of the D programming language, I was asked to take over the role going forward. It’s needless to say, but I’ll say it anyway, that those are some pretty big shoes to fill. I’m still settling into my new role in the community and figuring out how … Continue reading My Vision of D’s Future
Read more...Ownership and Borrowing in D
Posted onNearly all non-trivial programs allocate and manage memory. Getting it right is becoming increasingly important, as programs get ever more complex and mistakes get ever more costly. The usual problems are: memory leaks (failure to free memory when no longer in use) double frees (freeing memory more than once) use-after-free (continuing to refer to memory … Continue reading Ownership and Borrowing in D
Read more...Using const to Enforce Design Decisions
Posted onThe saying goes that the best code is no code. As soon as a project starts to grow, technical debt is introduced. When a team is forced to adapt to a new company guideline inconsistent with their previous vision, the debt results from a business decision. This could be tackled at the company level. Sometimes … Continue reading Using const to Enforce Design Decisions
Read more...Lost in Translation: Encapsulation
Posted onD programmers come from a variety of programming backgrounds, C-family languages perhaps being the most common among them. Understanding the differences and how familiar features are tailored to D can open the door to more possibilities for organizing a code base, and designing and implementing an API. This article is the first of a few that will examine D features that can be overlooked or misunderstood by those experienced in similar languages.
Read more...Go Your Own Way (Part Two: The Heap)
Posted onThis post is part of an ongoing series on garbage collection in the D Programming Language, and the second of two regarding the allocation of memory outside of the GC. Part One discusses stack allocation. Here, we’ll look at allocating memory from the non-GC heap.
Read more...D as a Better C
Posted onThere are large and immensely useful programs written in C, such as the Linux operating system and a very large chunk of the programs written for it. While D programs can interface with C libraries, the reverse isn’t true. C programs cannot interface with D ones. It’s not possible (at least not without considerable effort) to compile a couple of D files and link them in to a C program. The trouble is that compiled D files refer to things that only exist in the D runtime library, and linking that in (it’s a bit large) tends to be impractical.
That is, until Better C came along.
Read more...Don’t Fear the Reaper
Posted onD, like many other programming languages in active use today, comes with a garbage collector out of the box. There are many types of software that can be written without worrying at all about the GC, taking full advantage of its benefits. But the GC does have drawbacks, and there are certainly scenarios in which … Continue reading Don’t Fear the Reaper
Read more...