rust
Understanding the Strategy Pattern
Apr 3, 2022
programming
concepts
rust
exercises
Conditionals (if, switch, and match statements) are usually the first programmers reach for when we need to vary the execution of a function. They’re easy to understand and convenient to use, as long as the variations are simple. As software grows, though, extensibility and comprehensibility begin to require that we create ways to “hook” new functionality into our functions. The strategy pattern offers a method to accomplish that:
Define a family of algorithms, encapsulate each one, and make them interchangeable.
Rust Needs Metaphors, Part 2: Traits
Oct 14, 2020
programming
rust
When I began learning Haskell, typeclasses were confusing to me: at first, because I didn’t fully understand why they were needed, and later, because I didn’t understand the advantages they offered over Java’s interfaces. If you’re new to Rust but haven’t used Haskell before, you’ll likely be in the same boat, but moreso; traits are pervasive in the ecosystem.
At heart, traits are very similar to interfaces in Java or C♯.
Rust Needs Metaphors, Part 1: Lifetimes
Sep 19, 2020
programming
rust
I recently had a conversation with a friend who said: “I don’t trust most of what I hear about Rust, because it sounds like agitprop from the Rust Evangelism Strike Force, but people like you whom I trust and respect seem to like it. Can you help me understand why?”
I tried to. I said things that make sense, in the abstract: it offers a very powerful type system, it allows me to feel more confident about my code in surprising ways, and so on.