DEV Community ๐Ÿ‘ฉโ€๐Ÿ’ป๐Ÿ‘จโ€๐Ÿ’ป

DEV Community ๐Ÿ‘ฉโ€๐Ÿ’ป๐Ÿ‘จโ€๐Ÿ’ป is a community of 963,274 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
Leslie Tang
Leslie Tang

Posted on

Notes on "Clean Code" Chapter 1: "Introduction"

Introduction

I've always heard of this book "Clean Code" by Robert C. Martin. In school, there really wasn't much of a pressure to write or maintain clean code. Mainly because we probably will only touch the code during that 13 weeks of semesters. On top of the deadlines and preparing for assignments, writing clean code is almost never my priority.

After starting my own side project, the thought of having to deal with my messy code in the time to come quickly prompt me into reading this book that I've been pushing away for so long.

This series is meant to be my notes on the book. While serving as a platform for discussion on the book.

Chapter 1: Clean Code

Three Takeaways

  1. Clarity of Thought
    As I read the first chapter, the first thought that comes into my mind is the need for clarity of thought. Perhaps the reason my code is messy because I jumped in without having enough knowledge and experience on how to structure my web application. As I come across problems, my natural responses tend to be a quick google search rather than thinking about it for myself. This leads to the accumulation of "spaghetti code".

  2. Importance of Caring for your Code
    "Clean code always looks like it was written by someone who cares. - by Michael Feathers" This quote from Michael Feathers really hit me, perhaps the reason why I've been writing messy code is that I've been caring for the wrong things! What sort of wrong things? Prioritizing school work that grades you based on the passing of test cases and launching of an application ASAP. When I read this quote, I felt ashamed of myself.

  3. Reading to Writing Ratio
    In the book, Martin brought up an example illustrating that the ratio of reading to the writing of code is well over 10:1. Though my own experience, I do agree that I spend a lot more time reading than writing new code. Which is also one of the reasons which compelled me to start reading this book. One of the ideas that came to mind is to start drawing diagrams or models to facilitate the reading of code in the future. Even better if those diagrams/models are interactive. I would imagine it would be a lot easier to navigate through a huge code base than scrolling through seemingly infinite lines of code.

Conclusion

I'll conclude with two personal action plan:

  1. Before I write code, start by having an implementation plan in the form of diagrams or flowchart. This should improve my clarity of thought.

  2. Start thinking about yourself in the future (or your team members). Caring about your code is very similar to caring for the people that will work on your code next. Delay the need for speed and increase the need for care.

Top comments (6)

Collapse
 
jwulf profile image
Josh Wulf • Edited on

Great article!

Another thing they won't teach you in school is that "there is no such thing as good coding, only good refactoring".

"Perhaps the reason my code is messy because I jumped in without having enough knowledge and experience on how to structure my web application."

The reason is that good structure only arises out of refactoring, as concerns are distinguished, and are then extracted to separate them cleanly. Up-front planning also helps, but refactoring is essential. Martin Fowler's book "Refactoring" (both editions), and the book "Refactoring JavaScript" are both good.

Collapse
 
tangweejieleslie profile image
Leslie Tang Author

Thanks!

"There is no such thing as good coding, only good refactoring"

That makes a lot of sense! Though to be fair, I guess the school did teach us that through having multiple iterations throughout the semester. But I guess I'm too thickheaded to realize that...

Will pick up your recommended book perhaps after I'm done with this book ๐Ÿ˜

Collapse
 
badrecordlength profile image
Henry ๐Ÿ‘จโ€๐Ÿ’ป

At my university we are marked on code quality in addition to functionality, with a higher weighting on functionality. When trying to meet uni deadlines I usually first try to write code that just works (and often think to myself, "this isn't a great way of doing this but I bet I can make it better") and then, once working, revisit to experiment and to write it in a better way. This method has worked well for me so far.

Collapse
 
tangweejieleslie profile image
Leslie Tang Author

Nice approach! Actually, I do have a few modules that have some grading on code quality in the beginning. Ultimately, it is more of my personal fault for prioritizing short-term goals during the semester.

Collapse
 
bhupesh profile image
Bhupesh Varshney ๐Ÿ‘พ

I have just ordered this book
๐Ÿ˜‹๐Ÿ˜‹

Collapse
 
tangweejieleslie profile image
Leslie Tang Author

Nice! ๐Ÿ˜„

Update Your DEV Experience Level:

Settings

Go to your customization settings to nudge your home feed to show content more relevant to your developer experience level. ๐Ÿ›