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 code slightly uglier to save an implicit Iterator allocation:
for (int i = 0, size = protocols.size(); i < size; i++) {
Protocol protocol = protocols.get(i);
if (protocol != Protocol.HTTP_1_0) {
result.writeByte(protocol.toString().length());
result.writeUtf8(protocol.toString());
}
}
Java 8 invites me to make the opposite tradeoff: to use streams and lambdas like a functional programmer:
protocols.stream()
.filter(protocol -> protocol != Protocol.HTTP_1_0)
.forEach(protocol -> {
result.writeByte(protocol.toString().length());
result.writeUtf8(protocol.toString());
});
Here we’ve got three perfectly-reasonable ways to write the same code, and therefore the perfect opportunity to have a disagreement on how this loop should be written.
When a programming language, API, or design pattern is seductive its cosmetic beauty hides its structural limitations. I’m frustrated when making my code read better harms how efficiently it runs or how maintainable it is.
Seductive and Slow
Recently


How your brain works.
In Terminator, Skynet just launches the nukes. In Daemon, the AI is much better: it uses coercion!
Feedback loops and failure.
“I'm gonna have to science the shit out of this.”