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…

Optimization is Specialization

One aspect of programming that’s more art-than-science is making things efficient. I love finding shortcuts that make a system work better! It’s particularly satisfying to gather insights that we can exploit! I’ll illustrate with an example. Optimal for TodayHttpUrl is a class I wrote that implements URL…

Induced Demand & Code

This post expands on a section in my Writing Code That Lasts Forever talk. Here's what it takes to release a new version of OkHttp: Confirm the code is in a releasable state!Name the version (5.0.0-alpha.10 ?, ick)Summarize what’s new in the changelogTag the release…

Selection Bias in Hiring & Promotions

Let’s make a fictional company that employs workers in two levels: Senior worker: does important work; gets paid $50/hour.Principal worker: trusted with the most important work; gets paid $100/hour.Unfortunately, it’s difficult to differentiate the two levels! If a project completes early it might because…