Designing Languages and Libraries

November 14, 2020

I haven’t written much code in Swift. But as a C++ developer, I found John Sundell’s interview with Dave Abrahams (recommended by Michael Tsai) on the Swift by Sundell podcast fascinating.

Abrahams, on first encountering the C++ STL:

But there were no libraries. And when the STL came along, it really changed my life, because not only did it give me some tools that I could just use, but these tools were composable in a way that I had never seen before.

[…]

They were documented in a way that you could really use these components without looking inside them at their implementations. And they provided kind of a framework for thinking about a whole range of problems.

I never programmed in C++ without the STL being available. It’s so fundamental to my personal notion of ideal C++ code, I cannot imagine writing C++ without it.

On value semantics:

The other aspect of protocol-oriented programming that I left out was how it enables polymorphism with value semantics. And when I say value semantics I mean something very specific. There are functional programming languages where everything is immutable. And those are all values. But that’s not what I think of as interesting value semantics. Interesting value semantics is mutable value semantics.

Later:

One of the fundamental sources of bugs that we have in software today is shared mutable state. It’s terrible for threading, and it’s sort of an invitation to race conditions if you’re doing multi-threading. But it’s also just a source of bugs in regular code. I mentioned functional programming languages deal with this by making things immutable. Which is a really interesting approach, but it’s really costly. Because, the basic model of your machine is one with mutation. You’ve got a memory and you can write to it, right? So what happens when your language takes you a good distance away from the machine model? That means that the compiler has to do a huge amount of work to recover the efficiency of using the features of the machine.

If you are interested in language or library design, give this episode a listen.