Rust doesn't solve the CrowdStrike outage

Look, I like Rust. I really, really do, and I agree with the premise that memory-unsafe languages like C++ should not be used anymore. But claiming that Rust would have prevented the massive outage that the world went through last Friday is misleading and actively harmful to Rust’s evangelism. Having CrowdStrike written in Rust would have minimized the chances of the outage happening, but not resolved the root cause that allowed the outage to happen in the first place. Thus, it irks me to see various folks blanket-claiming that Rust is the answer. It’s not, and pushing this agenda hurts Rust’s adoption more than it helps: C++ experts can understand the root cause and see that this claim is misleading, causing further divide in the systems programming world. So, why won’t Rust help? Let me try to answer that question, but while we are at it, let’s also delve deeper into the causes of the outage. In a way, let me put my SRE hat on and write my own version of the postmortem.

July 23, 2024 · Tags: blogsystem5, opinion, rust
Continue reading (about 12 minutes)

Porting the EndBASIC console to an LCD

Hello again Blog System/5 and sorry for the radio silence for the last couple of months. I had been writing too much in here and neglecting my side projects so I needed to get back to them. And now that I’ve made significant progress on cool new features for EndBASIC, it’s time to write about them a little! One of the defining characteristics of EndBASIC is its hybrid console: what looks like a simple text terminal at first glance can actually render overlapping graphics and text at the same time.

April 26, 2024 · Tags: blogsystem5, endbasic, rust
Continue reading (about 16 minutes)

How "new type" helps avoid production outages

My January links recap included the “Phantom Types” article by David Soria Parra. In it, the author briefly touches upon the “new type” idiom, its typical implementation in Rust, and then proceeds to propose a better alternative. But the question arises: why should you care? To answer why this idiom is useful, I want to present you with a real production problem we faced in the Storage Infrastructure team at Google circa 2010.

March 9, 2024 · Tags: blogsystem5, rust, sre, twitter-thread
Continue reading (about 4 minutes)

5 ways to instantiate Rust structs in tests

I’m a big fan of static typing and I’ve found that using narrow types for each entity in the object model of my programs reduces errors. Rust is particularly well-suited at this task: its lack of implicit type conversions eliminates surprises, and its ownership semantics allow type transformations with zero cost. Unfortunately, (ab)using narrow types in an app’s domain is really annoying when writing tests. While non-test code rarely instantiates new objects—in the case of a REST service, this would only happen at the service’s boundaries—tests instantiate objects infinitely more times than non-test code. Code patterns that may seem reasonable in non-test code can become unbearable in tests. In this post, I want to look into the various ways in which you can instantiate strongly-typed objects. For each, I show examples and describe their pros and cons. And yes, as a matter of fact, I have tried them all before… and I can’t yet make my mind as to which one is best.

October 6, 2023 · Tags: programming, readability, rust
Continue reading (about 10 minutes)

A failed experiment with Rust static dispatch

Initial versions of the EndBASIC Service, and therefore initial versions of EndTRACKER, used dynamic dispatch to support abstract definitions of system services such as the database they talk to and the clock they use. This looked like a bunch of Arc objects passed around and was done to support extremely fast unit testing. When I generalized the core logic of these services into the III-IV framework, I decided to experiment with a switch to static dispatch. The rationale was that using static dispatch better aligns with the design of well-regarded crates in the Rust ecosystem, and also because I wanted to avoid unnecessary runtime costs in the foundational pieces of my web services. Let me tell you that this decision was a huge mistake and that the experiment has utterly failed. Using static dispatch has been a constant source of frustration due to the difficulty in passing types around and reasoning about trait bounds. The situation had gotten so bad that I dreaded adding new functionality to my services whenever a change to a statically-typed struct was needed, because that meant adding yet another type parameter and plumbing it through tens of source files. In lieu of the difficulties, which eventually turned into blockers to implementing new features, I made the choice of going back to dynamic dispatch. The goal was to gain ergonomics at the expense of a supposedly-negligible runtime cost. Let me tell you about the problems I faced, the refactoring journey, and some measurements I gathered after the rewrite.

August 6, 2023 · Tags: endtracker, iii-iv, programming, rust
Continue reading (about 13 minutes)

Unit-testing a web service in Rust

One of the things I'm most proud of the Rust web services I have written is how I can run their tests with zero setup and within milliseconds, all while making me confident that "main" can always be shipped to production. I've previously touched upon how this all works in other articles, but it's time for a deep dive. To make things specific, I'll be describing the testing infrastructure of EndTRACKER, the EndBASIC Service, and the sample key/value store app of III-IV. These services are all structured in three separate layers, and I'll be covering the testing strategy for each of them.

July 7, 2023 · Tags: endbasic, endtracker, iii-iv, programming, rust
Continue reading (about 19 minutes)

A persistent task queue in Rust

A couple of posts ago, I described why I built custom email subscriptions for this blog. I briefly mentioned that there is new automation that scrapes the RSS feed and sends new post notifications to you all. Today, it’s time to look into how this all works and how this is based on a new persistent task queuing service in Rust. The queue handles tasks to periodically scrape the RSS feed and schedule emails, all with various quota enforcers and retry policies in place. Read on for the design requirements and constraints of the task queue, how the client and worker Rust APIs look like, and how this all can be made to work inside the Azure Functions serverless runtime for minimal deployment hassle and cost.

June 23, 2023 · Tags: endtracker, iii-iv, rust
Continue reading (about 17 minutes)

From AST to bytecode execution in EndBASIC

Since its inception two years ago, the EndBASIC interpreter has been using an AST-based execution engine. And during all this time, people have mocked the language for not allowing 10 GOTO 10. Well, fear not: the upcoming 0.10 release has full support for GOTO and GOSUB, features that were made possible by moving to a bytecode-based interpreter. Let’s take a peek at what the problems were and how I addressed them.

November 22, 2022 · Tags: endbasic, rust
Continue reading (about 9 minutes)

Rust is hard, yes, but does it matter?

Rust is infamous for having a steep learning curve. The borrow checker is the first boss you must defeat, but with a good mental model of how memory works, how objects move, and the rules that the borrow checker enforces, it becomes second nature rather quickly. These rules may sound complicated, but really, they are about understanding the fundamentals of how a computer works. That said… the difficulties don’t stop there. Oh no. As you continue to learn about the language and start dealing with things like concurrency—or, God forbid, Unix signals—things can get tricky very quickly. To make matters worse, mastering idiomatic Rust and the purpose of core traits takes a lot of time. I’ve had to throw my arms up in frustration a few times so far and, while I’ve emerged from those exercises as a better programmer, I have to concede that they were exhausting experiences. And I am certainly not an expert yet. So, yes, there is no denying in saying that Rust is harder than other languages. But… does it matter in practical terms? Betteridge’s law of headlines says that we should conclude the post right here with a “no”—and I think that’s the right answer. But let’s see why.

May 6, 2022 · Tags: featured, opinion, rust
Continue reading (about 4 minutes)

Do Rust devs hate Go devs?

Earlier this week, a 2-year old post titled I want off Mr. Golang’s wild ride by @fasterthanlime made the news rounds again. This post raises a bunch of concerns on the Go language and is posted from the perspective of someone who prefers Rust. And, just yesterday, I noticed a comment on Twitter by @FiloSottile that, paraphrased, reads “Why is there so much hatred towards Go, especially from Rust developers?”. I wish I could answer this question with a “no, there isn’t”, but that would be a lie: in any large community, there will certainly be hateful people/opinions. If you have encountered such flamebait, I’m sorry, and I’m not here to defend it. What I’m here to do is look at the possible truth behind the claim that Rust developers dislike Go, and I wanted to elaborate on this based on my personal experience.

April 29, 2022 · Tags: go, opinion, rust
Continue reading (about 6 minutes)

Rust traits and dependency injection

Dependency injection is one of my favorite design patterns to develop highly-testable and modular code. Unfortunately, applying this pattern by taking Rust traits as arguments to public functions has unintended consequences on the visibility of private symbols. If you are not careful, most of your crate-internal APIs might need to become public just because you needed to parameterize a function with a trait. Let’s look at why this happens and what we can do about it.

April 22, 2022 · Tags: featured, rust
Continue reading (about 9 minutes)

Introducing db_logger

Over the last couple of weeks, I have been modernizing the codebase of the EndBASIC cloud service by applying many of the learnings I got from the development of EndTRACKER. The latter was a fork of the former and thus the foundations were the same, but as I iterated on the latter more recently, I got to refine my approach to writing a REST API in Rust. During this refactoring process, there was a small piece of the system that routinely got in the way for various reasons. This piece was the “database logger”.

April 12, 2022 · Tags: db_logger, rust, software
Continue reading (about 3 minutes)

EndBASIC 0.6 release announcement

After a very active month of development since the 0.5 announcement, it is time to welcome EndBASIC 0.6! This new 0.6 release is super-exciting for three reasons: preliminary GPIO support in the standard library specifically tailored to the Raspberry Pi; multidimensional array support in the language; and availability of binary releases for the most common platforms. You can dive right in by: visiting https://repl.endbasic.dev/ for an interactive session, reading more about the project at https://www.

February 19, 2021 · Tags: endbasic, programming, release, rust
Continue reading (about 8 minutes)

Embedding EndBASIC into a (Rust) program

One thing that bothers me quite a lot about various language implementations is that the core of their interpreter isn’t clearly separate from their standard library. This makes it hard to embed those interpreters into other programs because it’s not obvious how to limit their side-effects and because the interpreter dependency can be heavy. In this post, we will see how EndBASIC’s design tries hard to keep the core as small as possible, and we will see some examples on how to use EndBASIC from Rust and vice versa.

January 26, 2021 · Tags: endbasic, programming, rust
Continue reading (about 7 minutes)

EndBASIC 0.5 release announcement

A month has passed since the 0.4.0 announcement so it is about time to say hello to yet another EndBASIC release because 0.5.0 is here! So, what’s new? Not much… unless you look under the covers, in which case a ton has changed. About 30% of the codebase has been affected in one way or another to improve general quality, so read on to see how.

January 24, 2021 · Tags: endbasic, programming, release, rust
Continue reading (about 3 minutes)

Enforcing code health via GitHub Actions

It is no secret that, in software development, the edit+build+test cycle must be as short as possible. The delay between saving a file and seeing the results has to be minimal and in the order of a few seconds, or else developers lose focus and productivity suffers. It’s equally important to ensure that the code is held to certain quality standards. Compiler warnings, for example, are part of any compilation and catch a set of common problems.

January 8, 2021 · Tags: automation, ci, rust
Continue reading (about 9 minutes)

EndBASIC 0.4 release announcement

About a month ago and after a long hiatus, I published EndBASIC 0.3 and the adrenaline rush that came with it got my wheels spinning again full-steam ahead. So here I am today, ready to announce the 0.4 release. But… “what could have possibly changed in just a month of someone’s free time”, you wonder? Enough, actually! EndBASIC 0.4 is the release that fulfills my original goal of being able to run a “guess the number” game.

December 25, 2020 · Tags: endbasic, programming, release, rust
Continue reading (about 13 minutes)

Unit-testing a console app (a text editor)

The most notable feature in EndBASIC 0.3 is its new full-screen console-based text editor. In this post, I describe why it is important and useful to unit-test a console app like this, and I will dive into how to implement unit tests that catch regressions and inefficiencies. Code samples are in Rust, but the concepts presented here are applicable to any language with minimal data abstraction facilities.

December 8, 2020 · Tags: endbasic, featured, programming, rust
Continue reading (about 16 minutes)

Using the builder pattern to define test scenarios

I’ve been playing with the builder patter to express test scenarios in a succinct and declarative manner. I’ve liked the outcome and feel that this design can yield to pretty good test code, so I’ll dig through this idea here. Note that, while this post and the associated code talk about Rust, the ideas presented here apply to any language. So don’t leave just because I said Rust!

December 4, 2020 · Tags: endbasic, programming, rust
Continue reading (about 6 minutes)

EndBASIC 0.3 is here

After a 6-month long hiatus caused by me hunting and changing jobs and cities, I am pleased to announce the release of EndBASIC 0.3! The Thanksgiving break has been as fruitful as I had hoped 😁 There are two major changes in this release. The first is the official debut of the web-based interface. I introduced this months ago and have had it running on a “push on green” model, which means that the web deployment of EndBASIC is always tracking Git HEAD.

November 29, 2020 · Tags: endbasic, programming, release, rust
Continue reading (about 2 minutes)

Bridging the web gap in EndBASIC

After a ton of work, a lot of which was unexpected, I am ecstatic to announce that EndBASIC is now a reality on the web! The whole language interpreter can now run as a fully client-side web app on a computer, on a tablet… and even on a phone. Yes: the whole thing, which is written in Rust (94%), works in a modern browser with just a tiny bit of JavaScript glue (1%).

May 30, 2020 · Tags: endbasic, programming, rust
Continue reading (about 7 minutes)

EndBASIC 0.2.0 is here

A couple of weeks ago, I announced EndBASIC: a simple BASIC language interpreter written in Rust with a goal to provide an environment for teaching my kids how to code. That first release provided what-I-think-is a robust interpreter, but that was about it: the language features were still minimal and the interactive features were non-existent. Well, EndBASIC 0.2.0 is here and things are changing! It’s still far from the vision I want to reach, but it’s slowly moving towards that direction.

May 7, 2020 · Tags: endbasic, programming, release, rust
Continue reading (about 6 minutes)

What is Rust's Into<T> for?

Rust provides a bunch of traits that you may use or implement in your code, but unless you have experienced them first-hand, it can be hard to imagine what their real utility is. For example, if you go read Into’s documentation, all you find is: Trait std::convert::Into A value-to-value conversion that consumes the input value. The opposite of From. […] Yay, very useful. This text tells me what this trait does, which is fine for a reference manual, but not when I could find it useful.

April 27, 2020 · Tags: programming, rust, sandboxfs
Continue reading (about 4 minutes)

Hello, EndBASIC!

Introducing EndBASIC, a new interpreter for a BASIC-like language that is inspired by Amstrad’s Locomotive BASIC 1.1 and Microsoft’s QuickBASIC 4.5. Like the former, EndBASIC intends to provide an interactive environment that seamlessly merges coding with immediate visual feedback. Like the latter, EndBASIC offers higher-level programming constructs and strong typing. The main idea behind EndBASIC is to provide a playground for learning the foundations of programming in a simplified environment.

April 22, 2020 · Tags: endbasic, featured, programming, release, rust
Continue reading (about 3 minutes)

Sample REST interface in Rust and Go

Over the summer, I prototyped a bunch of web apps whose ideas had been floating in my mind for a long time. I spent some time reading through REST API documentation pages and, as part of these exercises, implemented sample RESTful web services in both Go and Rust. (Just for context, the last time I wrote a web app was in high school… and it involved PHP, MySQL, and I think IE6?

September 27, 2019 · Tags: featured, programming, rust, webapp
Continue reading (about 16 minutes)

Rust vs. Go

There is no good answer to this question: people tend to put Go and Rust in the same bucket because they were released at around the same time, because Rust’s release felt like a response to Go’s, and because they are marketed to similar audiences. They are, however, vastly different. So let’s give in and compare them anyway.

July 13, 2018 · Tags: featured, go, programming, rust, sandboxfs
Continue reading (about 13 minutes)

Rust review: Closing thoughts

Thought that the Rust review was over? Think again; I was just on vacation! I’m back now to conclude the series with a bunch of random thoughts and a surprise follow-up post. The series is coming to an end. It’s time to summarize everything we have discussed so far and to cover a few more items that didn’t really deserve full posts of their own. Most of these miscellaneous items were thoughts that I jotted down while reading TRPL book.

July 10, 2018 · Tags: programming, rust
Continue reading (about 5 minutes)

Rust review: The ecosystem

In this part of the review, I would like to focus on Rust’s ecosystem: in other words, how Rust plays with other parts of a functioning system and how Rust’s standard library vs. external libraries interact with each other. There are a lot of pieces to cover in these areas and they have left me with mixed feelings. Let’s look at some. The standard library The std library feels generally well-thought out and full of features.

June 22, 2018 · Tags: programming, rust
Continue reading (about 4 minutes)

Rust review: The book

“The Rust Programming Language” is one of the free books that the community has put together to teach the language. The book does a good job in general, but there are some things that could be better. Let’s cover these, but first, some background. A couple of years ago, right after getting started with Rust, I tried to go through the book’s first few chapters. It all sounded cool… but the first edition of the book moved at a glacially slow pace because it covered things in excruciating detail.

June 19, 2018 · Tags: programming, rust
Continue reading (about 4 minutes)

Rust review: The match keyword

A commonly-acclaimed feature of Rust is its match keyword: a “conditional on steroids”. match lets you take the value of an expression and compare it against a bunch of values—or, more generally, patterns. As you write and read Rust, you will notice that this keyword is used everywhere because it’s the way to access certain types, like Option values or error codes. For example: match node.get_parent() { // node is an Option<Something>.

June 15, 2018 · Tags: programming, rust
Continue reading (about 3 minutes)

Rust review: Expressions, expressions, expressions

Rust resembles a functional language in many ways although it does not claim to be one. In fact, I have been thinking of Rust as a “pragmatic Haskell” or as a “well-balanced mixture between C++ and Haskell”. One of the ways the functional aspects show up is via expressions and how pretty much any construct in Rust can be treated as an expression. But before we begin, a little warning: the examples below are, by no means, idiomatic Rust—I just hope they are simple enough to illustrate what I want to show.

June 12, 2018 · Tags: programming, rust
Continue reading (about 4 minutes)

Rust review: Learning curve

Writing Rust code is not restricted to programming gurus—but there is no denying that the learning curve is steeper than that of other languages. Or is it? In this post, I’ll try to convince you that the curve does feel steep, but it isn’t when taken into perspective. Let’s first start by stating that learning a language is not the same as learning its syntax. Learning a language involves learning the syntax, of course, but it also involves familiarizing oneself with its common idioms and grabbing a good sense of what the standard libraries provide.

June 8, 2018 · Tags: programming, rust
Continue reading (about 4 minutes)

Rust review: Protect the data

The one thing that blew my mind about Rust is its approach to data sharing in concurrent situations. I had always thought of mutexes as something that is easy to get wrong and was convinced that the use of a RAII pattern to prevent lock leaks never happen (like with Abseil’s MutexLock) was the panacea. (I’m a fan of RAII in C++ by the way, in case you haven’t noticed.)

June 5, 2018 · Tags: programming, rust, sandboxfs
Continue reading (about 5 minutes)

Rust review: The borrow checker

Aaaah, the borrow checker: the dreaded enemy lurking within the Rust compiler, ready to make its move to bring pain to your life by preventing your code from compiling. Or that’s what everyone seems to say, which is one of the reasons I put off learning Rust for so long. In reality… the borrow checker is a blessing, but it is true that getting past its gates is difficult at first.

June 1, 2018 · Tags: programming, rust, sandboxfs
Continue reading (about 3 minutes)

Rust review: Immutable by default

Let’s start the deep dive by looking into a powerful feature of Rust: all variables and references are immutable by default unless qualified with mut. To understand why this is important, let’s cover some context first. One of my pet peeves when reviewing C++ code is to ask authors to sprinkle the const qualifier everywhere: if something ain’t mutated, say so explicitly. This includes marking local variables, function arguments, function return values, class attributes, etc.

May 29, 2018 · Tags: programming, rust
Continue reading (about 3 minutes)

Rust review: Introduction

I had been meaning to learn Rust since I first toyed with Go a couple of years ago. During this period, I’ve written a non-trivial amount of Go code both inside and outside Google, but never found the chance to sit back and learn Rust. This changed a month ago during my yearly family trip to Korea. This time around, I decided upfront that I would not work on any personal or work projects for the 2-week long vacation.

May 25, 2018 · Tags: programming, rust, sandboxfs
Continue reading (about 3 minutes)