# D as a C Replacement

Published , Updated

Tags: and

Sircmpwn (the main developer behind the Sway Wayland compositor) recently wrote a blog post about how he thinks Rust is not a good C replacement. I don’t know if he’d like the D programming language either, but it’s become a C replacement for me.

# Hello World Marketing (or, How I Find Good, Boring Software)

Published

Back in 2001 Joel Spolsky wrote his classic essay “Good Software Takes Ten Years. Get Used To it”. Nothing much has changed since then: software is still taking around a decade of development to get good, and the industry is still getting used to that fact. Unfortunately, the industry has investors who want to see hockey stick growth rates on software that’s a year old or less. The result is an antipattern I like to call “Hello World Marketing”. Once you start to notice it, you see it everywhere, and it’s a huge red flag when choosing software tools.

# Some Presentation Slides

Published

Tags: , , , , and

Here are the slide decks to a couple of talks I’ve given recently.

## Being Self-Employed in Australia (at JAIT)

Because this talk is based on my own experiences, it’s particularly relevant to service businesses in Australia. But if you’re interested in being your own boss, anywhere or anyhow, you could find it useful. As I said in the talk, there’s a lot of stuff that feels obvious to me now, but I ended up learning the hard way.

## Introduction to Infrastructure as Code (at RORO Sydney)

Here’s a common story: Devs write an app, and do all the right things like using source control and writing automated test suites. Then it comes to deploy the code, and they have to figure out all these things like DNS and server infrastructure. They hack something together using web UIs, but six months later no one can remember the deployment process any more.

This presentation was a really quick introduction to the tools you can use to get more app dependencies into source control.

# Why Sorting is O(N log N)

Published

Any decent algorithms textbook will explain how fast sorting algorithms like quicksort and heapsort are, but it doesn’t take crazy maths to prove that they’re as asymptotically fast as you can possibly get.

# D in the Browser with Emscripten, LDC and bindbc-sdl (translation)

Published

Here’s a tutorial about using Emscripten to run D code in a normal web browser. It’s uses a different approach from the Dscripten game demo and the dscripten-tools toolchain that’s based on it.

• Instead of porting the D runtime, it uses a lightweight, runtimeless -betterC build.
• It uses Docker to manage the Emscripten installation.

LDC has recently gained support for compiling directly to WebAssembly, but (unlike the Emscripten approach) that doesn’t automatically get you libraries.

You can find the complete working code on Github. ./run.sh starts a shell in a Docker image that contains the development environment. dub build --build=release generates the HTML and JavaScript assets and puts them into the dist/ directory.

This tutorial is translated from a Japanese post by outlandkarasu, who deserves all the credit for figuring this stuff out.

# Unfortunately, Garbage Collection isn't Enough

Published

Here’s a little story of some mysterious server failures I had to debug a year ago. The servers would run okay for a while, then eventually start crashing. After that, trying to run practically anything on the machines failed with “No space left on device” errors, but the filesystem only reported a few gigabytes of files on the ~20GB disks.

# Understanding a *nix Shell by Writing One

Published

Tags: , , , and

A typical *nix shell has a lot of programming-like features, but works quite differently from languages like Python or C++. This can make a lot of shell features — like process management, argument quoting and the export keyword — seem like mysterious voodoo.

But a shell is just a program, so a good way to learn how a shell works is to write one. I’ve written a simple shell that fits in a few hundred lines of commented D source. Here’s a post that walks through how it works and how you could write one yourself.

# Why it's Easier to Get a Payrise by Switching Jobs

Published

Tags: and

It’s an empirical fact that it’s easier to get a payrise if you’re negotiating a new job than if you’re negotiating within your current job. When I look back over my own career, every time I’ve worked somewhere longer term (over a year), payrises have been a hard struggle. But eventually I’d leave for a new position, and my new pay made all payrises at the previous job irrelevant. These days I make job switching upfront and official: I run my own business and most of my money comes from short contracts. Getting rewarded for new skills or extra work is nowhere near as difficult as before.

I know I’m not the only one to notice this effect, but I’ve never heard anyone explain why things might be this way.

# Using D Features to Reimplement Inheritance and Polymorphism

Published

Tags: , and

Some months ago I showed how inheritance and polymorphism work in compiled languages by reimplementing them with basic structs and function pointers. I wrote that code in D, but it could be translated directly to plain old C. In this post I’ll show how to take advantage of D’s features to make DIY inheritance a bit more ergonomic to use.

Although I have used these tricks in real code, I’m honestly just writing this because I think it’s neat what D can do, and because it helps explain how high-level features of D can be implemented — using the language itself.

# Hacking extern(C++) Classes to Work in betterC

Published

Tags: and

First up, here’s a big disclaimer if the title didn’t warn you enough: this is a hack. It’s just a proof-of-concept for getting extern(C++) classes working with betterC D. Also, DMD keeps getting better quickly, so if you’re reading this post when something more recent than version 2.080 is out, this hack is probably obsolete. Hopefully you’ll find this post interesting anyway if you’re either

• Interested in all things -betterC, or
• Curious about how stuff like classes work in D.

If you haven’t read my earlier post about how polymorphism and inheritance work yet, I recommend doing that first.