Tom Ritchford
3 min readNov 25, 2023

--

Very specific, actionable information without too much cruft: every technical article should be like this. These are the sorts of things you wouldn't notice in a couple of weeks but would drive you nuts, or thrill you, in a couple of years.

A photo I took of a double rainbow which has nothing to do with the article.

To be honest, you've sort of damped my enthusiasm for Rust slightly with that "cascading generic mess" example of yours. There really isn't another way?

C++ is notoriously tricky, and yet its templating system has several really good ways of reducing this complexity.

For example, a library can expose its types as a generic class with no members or methods that maps class names to actual classes at compile time in an intuitive way.

End-users can write code like this:

using some = some_library<std::vector<int>>;

auto appender = some::appender();

and never have to know that some_library<std::vector<int>>:::appender expands to some C++ monstrosity that is literally hundreds of characters in length!

(Well… unless they make some compile-time mistake, perhaps tiny, when often they will see the actual type in its entire glory, over and over again, but supposedly the language is getting better at that, and tooling can staunch the bleeding.)

Typing and I

Over a considerable period, I started with C(*), moved to C++ later, then Java, and then back to C++, but then out of the blue Python, for years completely untyped, grew from being an occasional scripting language to pretty well all my code this year so far.

In fact, the big change in my Python in the last year is that I had an opportunity to put typing into a moderate code base, and it was a revelation. Now everything(**) I write in Python is strictly typed.

Coming from strongly-typed languages, I had switched to Python because I was able to get a lot more done with a lot less programming, and almost never was performance an issue, because of numpy and other such libraries, even in doing real-time audio.

However, I started to write even bigger things and then it became hard to understand the code so development velocity would slow. Writing strictly-typed Python has locally slowed my coding down by around 1 part in 8, but has increased the reliability considerably.

My ability to write code that works the first time(***) has spiked, because my ability to correctly reason about the code has improved, because the typing tells me what I need to know, so in the medium-term, my productivity seems to be better, though yes, it’s hard to measure.

So I am reminded me of how C++ kept me safe, and I've been thinking about Rust, but, hmm, your article is making me wonder.

Perhaps I shouldn't be so fast to walk away from all that gooey C++ goodness!

Thanks for a good read.

(* — OK, I really started with calculators, Basic and then APL, so sue me.)

(** — Unit tests are only partly typed, mainly because if you typed your monkeypatching, you would reveal your cheating, but also because it’s a lot of work for really no value at all.)

(*** — I do have a definition for this. I don’t count name or punctuation typos immediately caught, or times I have to satisfy the type system with a bit more information. That aside, “working first time” means new code. and a full unit test that succeeds the first time it is run.)

--

--