Programming Leftovers
-
Python Data Classes vs Named Tuples: Differences You Should Know
Given that Python data classes are popular, are named tuples still relevant? What are the key differences between the two? Are there advantages of using one over the other—depending on what we’d like to do?
Let’s take a closer look at both data classes and named tuples, and try to answer these questions.
-
What's between a set and a sequence?
I finally updated the alloydocs to Alloy 6. The docs now cover how to use temporal operators in Alloy.
To celebrate, let’s talk something completely unrelated. The simplest kind of collection is the set: an unordered collection of unique elements. All branches of mathematics use sets somewhere, and in fact you can bootstrap all other collection types from just sets. Many programming languages have set types or something that mimics sets, but it’s less common than sequences, which are ordered collections of repeatable elements. ≈All programming languages have some form of sequence.
If sequences are sets + two properties, what are sets + one property?
-
The Goldilocks Zone of Indirection
I think there’s a Goldilocks Zone of indirection. Adding layers can be really powerful: it allows you to re-use code, isolate concepts, and can unlock some pretty rad ideas. But the mental overhead of indirection scales exponentially. By the third or fourth level you’re already losing track of what you were doing: I’ve had epic debugging sessions where I had to make like a pirate and draw a physical HERE BE DRAGONS style map and that’s not somewhere you want to go unless you really have to. Remember YAGNI. As I’ve learned and grown during my career I’ve really come to really appreciate taking a direct and simple approach rather than going for flexibility and power.
Of course, in the end the boring and adult answer to “how much indirection should I use” is “it depends.” Some parts call for more indirection, some parts call for less. But the arduous path from Rockstar Ninja to Senile Senior Developer has taught me that readability is far and away the most important property of any codebase. Be mindful of it whenever you feel like adding a layer of indirection. Stay in the Goldilocks Zone, so other humans can read what you’ve written. The computer doesn’t care either way.