read.engineerscodex.com

See also Work smarter, work slower and in a sense Digital Minimalism - Choosing a Focused Life in a Noisy World

Engineer’s Codex

5–7 minutes


Engineer’s Codex is a free publication about real-world software engineering. I write about real-world technical case studies, outages, and interesting stories from the industry.

When I was an undergrad, Leetcode broke my brain. I would see top solutions of esoteric one-liners and wrongly think “how do I ever get this good?”

This is commonly called “code golfing”. It’s a fun hobby, but very far from “good code.”

Everybody (including those on Leetcode) knows this isn’t good code. In the industry, it’s the worst code one could write.

Okay, I admit - this is a pretty bad example of clever code, because it is so obviously bad. Here’s an example of a code snippet I came across in some old code that I found annoying:

[

IMG-20241106232535796.jpg

](https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff4650fd1-cf7e-4d7b-94c9-cd121aff8864_1502x406.png)

However, on the other end of the spectrum, I realized eventually that the clearest code was actually the hardest to write.

It made sense retrospectively. Reviewing the code of a senior staff software engineer was much easier to follow and review compared to the code of an entry-level L3 engineer.

To be a top software engineer, you need to know a lot. But how do you know what you don't know? SWE Quiz is a compilation of 450+ software engineering and system design questions covering databases, authentication, caching, etc.

They’ve been created by engineers from Google, Meta, Apple, and more.

It’s helped many of my peers (including myself) pass the “software trivia questions” during interviews and feel more confident at work.

For a brief period of time, SWE Quiz is available for lifetime access.

Get Lifetime Access to SWE Quiz

"Debugging code is twice as hard as writing the code in the first place. Therefore, if you write code as cleverly as possible, you are, by definition not smart enough to debug it."

- Brian W. Kernighan

The “power” of clear code, for better or for worse, was made fully clear to me after a certain incident at work.

I once wrote a module in C++, a language that is a bit harder to read compared to other languages simply due to its verbosity.

I started with just two files (.h/.cpp) and all the implementation code went into just these two files.

The result was this giant, disgusting piece of spaghetti on the inside, but a perfectly working program on the outside.

This would never get past code review.

I split the implementation into 8-10 diffs. Each diff was a neat, containerized piece of code, with convenient placeholders for dependencies that would arrive in a later diff. It had code neatly split out into helper functions and helper files when necessary.

Each diff had reasonable unit test coverage - the basics and some obvious edge cases were covered, but I didn’t go wastefully overboard with it.

Each diff also took me quite a few iterations of “code cleaning,” refactoring, and more. It took a lot more effort than I expected to achieve “clear code,” especially for such a large program.

The result? A beautiful landing of the module, with easy to read, clear code.

While I was proud of it, there was suddenly a problem when I talked to my manager about it.

“While I understand how complex this was, when it comes to performance reviews, this code looks trivial. It looks too easy, too simple.

I would recommend writing an implementation doc of this module just so we can demonstrate that this was actually quite complex.”

I was shocked - this wasn’t some startup. This was one of the biggest companies in the world, known for their engineering culture.

I now understood why Big Tech seemingly had so many docs — half of the docs I wrote didn’t need to be written, except they did… because I wanted to get raises and be promoted.

While promotion culture in Big Tech is a story for another article (subscribe to see it in your inbox soon 🙂), the main point here is that great code is very clear and readable.

There’s a popular saying that debugging code is twice as hard as writing it. It’s the reason why when ChatGPT outputs some hogwash, it’s easier just to re-prompt it or write it from scratch yourself instead of trying to figure out the errors in its buggy code.

Clever code is harder to read and looks esoteric.

Clear code is harder to write and looks easy.