Preparing for Network Failures this Holiday Season

Suppose I’m connecting my home Christmas lights to the Internet. Perhaps I’ll make a mobile app that calls my home control server via an HTTP API: POST /lights/toggle HTTP/1.1 { "subjects": ["maple_tree", "roof"] }HTTP/1.1 200 OK { "toggled": true }It works. I can finally…

Your Company’s DanceService probably doesn’t Dance

I work on a big product at a big company and we have lots of backend services that have big responsibilities: The messaging service sends customers their emails, SMS messages, and push notifications.The banking service manages the customers’ bank accounts.The identity verification service verifies customers’ identities.Except that…

Farm or Grind

Suppose your organization has a widely-used internal library for validating customer usernames: private val usernameRegex = Regex("[a-z]{2,40}") fun isValidUsername(username: String): Boolean { return usernameRegex.matches(username) }The function becomes widely adopted: Some callers use it during customer sign-up. We don’t want customers putting slashes in their usernames!…

Read a File in a Kotlin/Multiplatform Test

I like writing unit tests that read test cases from a data file: Zipline does ECDSA and EdDSA signing. It gets test data from Project Wycheproof.OkHttp does URL parsing. It gets test data from The web-platform-tests Project.OkHttp-ICU does Unicode Normalization. It gets its test data from Unicode’s…

Bob Bent the Universe

Bob Lee was murdered on April 4 in San Francisco. I met Bob in 2006 when I joined him on the AdWords front end (AWFE) team at Google. He was charismatic, inventive, and kind. With Kevin B. he created Guice, a dependency injector that we could use to make AWFE…

Surprised by Re-entrant Code

Some of the trickiest bugs I’ve seen happened because a function unexpectedly occurred multiple times on the call stack. Re-entrant ListenersTo illustrate, consider a TextField widget that implements the listener pattern: class TextField { var listeners = mutableListOf<Listener>() var value: String = "" set(value) { val previous = field if (value…

Factory Factory

I use lots of factory classes in my code. But not everywhere. I don’t like the ceremony they require to create and use: why not a constructor? Factories don’t solve a business problem directly; they solve an architecture problem. They feel enterprisey and architecture astronauty. /** * For example, a…

Code Changes Should Be Small or Mechanical

Easy code changes are additive: introduce a new database table, network call, or screen. Difficult changes are transformative: split a database table, combine a few network calls, or change a component that’s used on many screens. These changes tend to motivate refactoring: Introduce feature flagsExtract interfacesMove code between modulesAdd…