I suggested Clean Code by Robert C. Martin[1] in my other post, compsci.learn(). I'd like to address some of the concerns people have with clean code. People find issue with the lack of comments, way that code should be broken down, and the performance of clean code. Casey Muratori made some analysis on performance and there's a great discussion between John Ousterhout and Robert C. Martin in Clean Code's appendix [1].

Documentation

Let's start talking about documentation. Clean code says that code should be self-documenting and should read like prose. "The proper use of comments is to compensate for our failure to express ourselves in code." [1, Ch. I, sec. 5, p. 1] We should be making our best effort to change the code so it says what it does.

This seems reasonable and at it's easiest, can be boiled down to this:

# === V1 ===
x = true
# While we're still doing work
while(x):
  # Do some work
  x = y.foo()
 
# === V2 === 
working = true
while(working):
  working = worker.work() != done
  

Saying verbatim what the code does is clearly a bad thing to do in a comment. V2 has less lines of code, and I don't have to switch languages from English to Python while parsing the code.

All comments are not created equal, and the previous example is terribly obvious. Sometimes, the code demands explaining, and names can get long. Long names are awkward, hard to parse, and "I don't see why a monster name is more likely to be "maintained" than a comment" John [1, Appendix: The Clean Code Debate, sec. Comments]. And R. C. Martin gave good explanations for two of the three cases, but I just want to talk about maintainability for a second.

It's much easier to delete a comment than it is to delete a function name. When I see a comment, I see something that doesn't impact functionality. It can be completely ignored- and I'm in good company when I ignore them because that's exactly what a compiler does. Function names cannot be ignored. They demand attention from any good programmer.

John brings up an example, addSongToLibrary(...), to illustrate that information is missing: title format, author order, duplicate songs, and where the song is stored. Does that information need to be put into a comment? I think there are several good ways to explain those pieces of information, worst of which is a comment:

/**
* Add a song to the library
*
* @param title             the title of the song, max 14 characters
* @param authors           the authors of the song, no nulls or empty strings
* @param durationInSeconds the song duration, greater than 0
*/
addSongToLibrary(String title, String[] authors, int durationInSeconds);

The javadoc comment is useful as part of a public API, such as Facebook's Messenger API. That is the only time I've found comments like javadocs to be helpful. It's specifically to let people know how their external inputs are going to be sanitized. It's from the perspective of an end user, not a developer. In a public API context, does the user ever need to know where the data is stored? Doesn't that encourage people to access or use knowledge about that data store directly, which is a bad form of coupling?

In most business software contexts beyond public APIs, I would use value types to make the code self-documenting:

addSongToLibrary(SongTitle title, SongAuthors authors, SongDuration duration)

Here you can clearly see something special is happening in the creation of the parameters; likely some validation is happening. Then, a developer can inspect the objects they care about or look at the unit tests. This is a valuable technique from Domain Driven Design which can be combined with builders to make your code say what it does.

Clean Code Caveat

For me, these are the main tools that Clean Code [1] will give it's readers:

  1. 1.

    Be polite

  2. 2.

    D.R.Y.

  3. 3.

    S.O.L.I.D.

  4. 4.

    Test!

These are all incredibly powerful ideas- and with great power comes great responsibility. I've seen several people complain that they wrote very bad code after reading Clean Code. Well, guess what? I promise that by using these tools, you will hurt yourself. I'll also say that, for myself, I wouldn't have it any other way.

I'm currently watching my son learn how to walk. He pulls himself up to couch-surf with no fear. He stumbles to and fro and, surprise, surprise, falls. If I'm not fast enough to catch him, he'll cry a bit and then with a kiss and rub he's right back at it.

Programming isn't easy. It's not simple. When you have a powerful toolbox like the one above, you'll fall. You'll also get back up, and with some retrospection, you'll realize that you used one of the clean code tools too much or in the wrong way. You certainly won't throw the tool away! You'll have more respect for how and when to use it.

Performance Issues

Casey Muratori's analysis on performance is super interesting. It points towards a deeper relationship to the compiler than I think most senior developers have. The analysis is a superb example of the importance of choosing either an object or a data structure [1, Ch.I, sec. 12]. However, this does a very poor job of discrediting even the first version of Clean Code.

There's a "fundamental dichotomy between objects and data structures: Procedural code (code using data structures) makes it easy to add new functions without changing the existing data structures. OO code, on the other hand, makes it easy to add new classes without changing existing functions." [2, Ch. 6] Choosing between the two is one of the reasons programming is hard. The performance differences that we're seeing in Casey's example could be a fantastic reason to choose one over the other.

I will also venture to say that this a very poor example of polymorphism. I'd be more curious if he could optimize a suite of different notification schemes:

public interface Notifier {
  void notify(Notification notification) throws MapperException;
}

public class EmailNotifier implements Notifier {
  void notify(Notification notification) throws MapperException {
    sendEmail(EmailMapper.toEmail(notification)); 
  }
}

public class TextNotifier implements Notifier {
  void notify(Notification notification) throws MapperException {
    sendText(TextMapper.toText(notification)); 
  }
}

Closed domain math, like calculating area, is only one problem space, one where procedural code might reign supreme. Network heavy cases may not have any noticeable improvement, and the pain wrought by putting all the different network dependencies in one file might be overwhelming. Beyond this, what if the whole point of making something polymorphic was so that someone else could extend the program, such as making a mod for a game? We wouldn't have the concrete knowledge needed to do any optimization.

All that being said, Casey is doing a fundamentally amazing thing by bringing performance into the spotlight. Ironically since he doesn't like Clean Code, he sure knows how to make clean code. I thoroughly enjoyed reading his c++ code and I almost felt like I knew what was happening even though I've barely ever touched c++.

To Clean or not to Clean

Professionally, I make it my mission to leave a legacy I'm proud of. I'm not proud if my code is hard to read, hard to understand, or hard to change. I'm not proud if my code is horribly coupled to a database implementation from the 90s. I'm not proud if it takes an eternity just to click a button. These are all important parts to my professional conduct and I would imagine they apply to more than just me.

References

[1] R. C. Martin, Clean Code: A Handbook of Agile Software Craftsmanship, 2nd ed. Boston, United States, Addison-Wesley Professional, 2026

[2] R. C. Martin, Clean Code: A Handbook of Agile Software Craftsmanship, London, England, Pearson, 2008