Skip to main content

Mike Kreuzer

Elixir and Rust - Mea culpa, mea maxima culpa

July 21, 2024

I've been down on Rust lately. Unfairly so. I may even have said – what I totally did say was – "Rust is a terrible language for game development. Probably a terrible language for any app with a GUI right now. Again there are things to like, but more things not to."

Mea culpa, mea maxima culpa. Rust can be a terrible language. It can certainly be used terribly. Lord knows, I've tried. But for the right sort of problem. Where the solution to the problem's framed in the right sort of way… it can work well. It does have a lot going for it. More than I may have implied (than I totally, literally said).

Even if the only thing Rust had going for it was that it wasn't beholden for its existence to one of the giant tech companies that would still be a lot. C# is only ever going to be as open source as Microsoft wants it to be. Kotlin is only ever going to do what Google tells JetBrains to do with it, and theirs is the only Kotlin IDE in town. Swift got result builders because Apple wanted them, & when Apple says jump the answer isn't ever going to be anything but a gung ho "how high?" But the problem Rust is used to solve has to be framed just so.

All of the pain (& a lot of the payoff) in Rust revolves around its rules for references. Any number of read-only ones, or just the one at any one time if it's a mutable reference. Which is fine if the problem's simple. Or small. Or both. It gets harder to do when a problem's large & changing as it's solved, which is what happens often in game development, but it can probably be done.

Rust is not the solution to every problem, & it is galling – which was the source of my, ahem, recent outburst… s (plural) – to be forced to jump through hoops when the business logic prevents the kind of race condition this is all meant to prevent from ever occurring any way. But that's probably a function of breaking up the problem the wrong way. Possibly. It's a baby/bathwater situation, not any kind of breach.

There's a great explanation of ownership on without.boats I read recently, in References are like jumps, & Ownership, that I wouldn't even attempt to summarise here. Interestingly Mojo & Lattner come up again in the context of value semantics. Less flatteringly, as you might guess.

While I'm at it…

The Elixir community on Reddit sucked, but is probably not necessarily all that representative of the Elixir community generally. I have been tempted by the language once or twice again over the years since bad mouthing it here & flouncing away from it. I could never really find a problem big enough to warrant solving with what Elixir brings to the table, but small enough that it couldn't already be done with some combination of other more readily available tools though. Add Redis for caching, Systemd for restarts, or whatever, & most any server-side language can do what Elixir does without having to leave the mainstream behind. (This may not be helping…)

I used Elixir in anger when I self hosted an instance on the Fediverse. That was with Akkoma. I never dug too deeply into the code, & was luckily never personally a victim of "Akkoma Database Rot", where the database gradually falls apart because of some strange schema/JSON choices made with it, so while I don't think I'd recommend it, for the short time I ran it, it ran OK. It wasn't the problem with self hosting.

I did also write a toy Gemini server in Elixir for fun just the other week. But I also wrote one in C#, Go, Python, Ruby, Rust & Swift too. I was interested in playing around with how the different languages deal with TCP & TLS connections, & with the Gemini Protocol. This is Gemini the minimalistic Gopher-like set up, not Gemini the Google AI model. It's really a very small thing a Gemini server, perfect to play with.

But none of that makes me an Elixir developer any more than it makes me a Go developer. Just a curious one. That much hasn't changed.