Notes on "Clean Code"? – How to Care for Code?

Notes on "Clean Code" – How to Care for Code?

Click here to read my notes on the Clean Code book from the beginning. In this post, I wrote what went through my head as I was reading Chapter 1:

It Starts with Why It Matters

A French philosopher, by the name of Guillaume Ferrero, discovered the Principle of Least Effort and wrote about it in 1894 – long before a single line of computer code, as we know it today, was written. Nevertheless, I can't help but think that, had he been alive to witness how most code is written, he would have demonstrated coding as the epitome of the least effort principle:

[Coding] stops as soon as minimally acceptable results are found.

Sounds familiar? Well, I'm sure it does, because we've all been there; once we find acceptable results, there's no immediate need to improve the current solution; we just want to get the task done, get that dose of instant gratification and move on to the shiny new project. Putting out fires and plugging holes are good examples of tasks that we don't want to revisit once we found a good enough fix; that notion is a perilous inclination, of which I've been a witness (and a culprit/victim) more times than I'd like to be. It's hard to resist the temptation of instant gratification; it takes discipline, self-control, and foresight to seek delayed gratification instead. A landmark psychological study, the Stanford marshmallow experiment, found a correlation between seeking delayed gratification and being more successful in life. I believe the same concept can be applied to code: we can stop at acceptable results, and have a cookie (pun intended) to celebrate checking off a box that says we're done, or we can strive for more, and have two cookies to celebrate the fruit of going the extra mile.

But is completing a task as tempting as enjoying a sweet treat? You bet! It may even be more tempting than you think; thanks to dopamine: a neurotransmitter connected to certain feelings like reward (completing tasks), and pleasure (enjoying sweets). Usually, code requires multiple iterations to reach acceptable results; and with each disappointing attempt, the level of dopamine that gets fired is reduced; when our code works – according to our acceptance criteria (test cases) – we get a pleasant surprise: increased levels of dopamine (Schultz et al). But why are we inclined to seek a new task after finding minimally-accepted results for the one at hand? According to Hilary Scarlett in Neuroscience for Organizational Change, "[dopamine] levels rise when we experience something new"; so it's no surprise that our brains seek more dopamine by making us want to move on to that shiny new task.

Yet, a pastor by the name of John Piper, once said:

...newness is no virtue and oldness is no vice. Truth and beauty and goodness are not determined by when they exist.

I'm sure that he wasn't referring to code when he said that, but you'll see why I quoted him if you replace "newness" with "a green-field project", and "oldness" with "legacy code". We should care for the code we inherited, and the code we are writing for others to inherit someday; we should exert more effort to keep on improving all code to reach a higher level of craftsmanship than what's minimally acceptable. Michael Feathers, author of Working Effectively with Legacy Code, eloquently stated:

Clean code always looks like it was written by someone who cares. There is nothing obvious that you can do to make it better.

In order to justify that extra effort, we need to have a good reason; otherwise, our actions will fade away because we weren't inspired to fight the uphill battle against our natural tendency to be lazy (by sweeping the messy code under the rug). That's why Uncle Bob, aka Robert Martin, inspires us like great leaders do: by starting with why it matters to keep our code clean.

It was the bad code that brought the company down.

In one of his examples, he talked about a killer app that was born into short-lived success marked by software bloat; later version started crashing, so users moved away; eventually, the company vanished, and its failure was traced back to bad code! I can relate to that, and so can many of you; I've learned – the hard way – how costly bad code could be; Uncle Bob is trying to change that, one reader at a time.

P.S. Caring for code is hard; watch this TEDx talk for ideas on how to do so; simply replace "global warming" with something like "code refactoring" and you'll see what I mean:


Gregory Zak

Principal Developer @ Booking.com

9 年

I've been looking for a way to describe clean code, and until that central quote, it's always been one of those "know it when you see it" sort of things. Now I know how to describe it. Great post!

Shane Ojeda

Insurance Agent at American Income Life

9 年

Worthwhile post

Molly Hindman

SW Management & ES design at JHA

9 年

This book, Clean Code, seems to have some interesting thoughts. The "least effort" principle also serves as a reminder that "science alone" as solutions for the world's problems is not a rational concept. The people providing those solutions must also care about the end results. Good engineering should involve caring about quality of work more than apparent success with a "quick fix."

要查看或添加评论,请登录

Mohamed El-Geish的更多文章

  • Managing the Organized Chaos That Is Software Development

    Managing the Organized Chaos That Is Software Development

    Disclaimer: This article was written mostly by GPT-3 given the first paragraph as a prompt; a few edits were made for…

  • On Perception vs. Reality & AI-Generated Media

    On Perception vs. Reality & AI-Generated Media

    Disclaimer: This article was written with the aid of GPT-3, given the first paragraph as a prompt; it's about 50%…

    1 条评论
  • Can AI Make Us Better Writers?

    Can AI Make Us Better Writers?

    Disclaimer: This article was written mostly by GPT-3 given the first sentence as a prompt; a few edits were made for…

    1 条评论
  • A Glimpse into the Future of AI

    A Glimpse into the Future of AI

    The pursuit of doing more is as old as history can recall: technology has been playing an important role in it from the…

    2 条评论
  • Reacting to Corrective Feedback

    Reacting to Corrective Feedback

    My brain used to freeze when someone points out a mistake I made; a sense of embarrassment and shame typically…

    2 条评论
  • A Stacking Ensemble for SQuAD2.0

    A Stacking Ensemble for SQuAD2.0

    Originally published at https://medium.com/@elgeish/a-stacking-ensemble-for-squad2-0-8513d96041ef — for the paper…

  • We Love Go; So Here's Gooseberry

    We Love Go; So Here's Gooseberry

    Read this on our blog: https://www.voicera.

  • 5 Books to Enjoy in 2018

    5 Books to Enjoy in 2018

    Work Rules! Laszlo Bock, the former head of people operations at Google, walks us through management lessons learned at…

    1 条评论
  • Learning from Hundreds of Resumes and Tens of Interviews in a Few Weeks

    Learning from Hundreds of Resumes and Tens of Interviews in a Few Weeks

    Hiring great employees is hard; ask any hiring manager, and you will hear war stories. I've had my share of those…

    5 条评论
  • Open-Sourcing Tester: Lightweight Go Test Utilities

    Open-Sourcing Tester: Lightweight Go Test Utilities

    At Workfit, we strive for building world-class software at a high iteration velocity. We heavily rely on open-source…

社区洞察

其他会员也浏览了