Modeling States vs. Facts

Lots of object models primarily track application state. For example, OkHttp’s Http2Connection.kt has state for whether a ping’s reply is outstanding: private var awaitingPong = false This is set to true each time a ping is sent and then false again when its reply is received. I’ve…

Naming Versions

I’m working on some code to sort software versions and it’s tricky. Maven Software that releases to Maven Central should follow Maven’s versioning scheme. This list is sorted by Maven’s scheme: 1.0.0-alpha 1.0.0-beta 1.0.0-rc1 1.0.0-RC2 1.0.0…

Kotlin’s Assert Is Not Like Java’s Assert

OkHttp uses synchronized as an allocation free mutex. Our concurrency model is tricky enough that we’ve documented the rules! And if we forget the rules, we also use runtime assertions to catch mistakes: @Override void flush() { // Make sure we don’t hold a lock while doing I/O! assert…

A Dependency Injector’s 3 Jobs

You can do dependency injection (DI) manually or with a library. Constructing your application’s dependency graph by hand is a cute exercise but not practical beyond toy examples. You’ll eventually find yourself extracting the repetitive manual DI code into your own bespoke library, one that’s likely to…

Value Objects, Service Objects, and Glue

This post expands on a section in my Writing Code That Lasts Forever talk. When I was learning object oriented programming I struggled to define boundaries between classes. Should a Chess game’s Bishop class have a move() method to reposition itself on the board? Should there even be a…

Factory or Extension Function?

I’m working on OkHttp’s Kotlin upgrade. Java callers use this code to go from a String to an HttpUrl: String string = ... HttpUrl httpUrl = HttpUrl.get(string); Should it remain the same in Kotlin? val string: String = ... val httpUrl: HttpUrl = HttpUrl.get(string) or should we follow the core…

Metrics for OkHttp’s Kotlin Upgrade

We’re upgrading OkHttp’s implementation language from Java to Kotlin. It’s a big process, especially as we’re maintaining strict compatibility with OkHttp 3.x. Fortunately we’ve done it before and we’re following the strategy Egor & I presented last year. Today we reached a nice…

Syntactic Sugar

In comparing programming languages I’ve found myself anchoring on what I’m comfortable with and seeing everything else as either “low level and verbose” or “full of syntactic sugar and magical”. I’ve recently gone from using mostly Java to using mostly Kotlin and I’ve learned that syntactic…