Story Code

Designing APIs is hard. One technique that helps me is to tell a story with the code: I’ll make a sequence of calls to show how things fit together. I find this helps me to discover what methods I need and what I can leave out. Using features together…

Name Your Threads

I work on a big Java service that does lots of things. When I snapshot the application’s threads I can see it’s got lots going on: Talking RPC and HTTP Running cron jobs and job queue jobs Persisting to MySQL Coordinating with ZooKeeper Collecting garbage At a glance…

Seductive Code

It’s careful work balancing tradeoffs when writing code and designing APIs. Here’s some everyday Java code: for (Protocol protocol : protocols) { if (protocol != Protocol.HTTP_1_0) { result.writeByte(protocol.toString().length()); result.writeUtf8(protocol.toString()); } } On Android—where garbage collector costs aren’t necessarily negligible—I make my…

Jesse, Learning in Anger

I’m using an open source library and it crashes in an unexpected way. The crash makes me grumpy because it prevents me from getting my real work done. I don’t want anyone to face this indignity ever again! And so I proceed to report the bug to the…

Charles 4 has HTTP/2

Karl von Randow has released Charles 4. “With Charles 4 you can now see HTTP 2 working, and you can use all of your familiar tools; Repeat, Breakpoints, and so on. You’ll spot HTTP 2 hosts in Charles as they use a different icon—with a lightning bolt!” I…

Java’s new HTTP client is upside down

One of Java 9’s new features is a replacement for HttpURLConnection. And while I’m thrilled to get rid of that old garbage its replacement has its own surprises. The Good The API is small. The new package is java.net.http and the Javadoc shows only 12 new…

The Last HttpURLConnection

An awkward API OkHttp 1.0 started out as an optimized implementation of HttpURLConnection. This old API is awkward to implement because there is an implicit state machine that corresponds to the underlying network I/O. GET / HTTP/1.1 Host: publicobject.com Accept: text/html HTTP/1.1 200…

The Open Source Maintainer’s Dilemma

We’re in a golden age of reusable open source code. With GitHub and Maven Central it’s never been easier to create and share code. This is excellent! Android developers have access to a steady stream of new projects. I keep up by following some Android developers on Twitter…