Washing your code

A book on clean code for frontend developers

About the book

We read code much more often than we write it — often to make a one-line change you have to read and understand hundreds of lines of code scattered among dozens of files. That’s why code readability is so important.

On dozens of examples, based on production code, I’ll show you how to make your code more readable and maintainable, and how to avoid hard-to-track bugs. I’ll show you code smells and antipatterns I often see during code reviews (and I review lots of code every day!) and will walk you through the refactoring process to make your code better.

These techniques help me every day to write code that my colleagues will have no problems working with. All book’s examples are written in JavaScript with a bit of TypeScript, React, CSS, and HTML.

Or read selected chapters below

Washing your code book cover

Table of contents

  • Avoid loops

    Working with iterations and why traditional for loops may not be the best way of doing that

  • Avoid conditions

    Writing good conditions and simplifying the code by avoiding them

  • Avoid reassigning variables

    Improving code readability by making it easier to understand what variables are doing and how they are used in the code

  • Avoid mutation

    Why mutation is hindering code readability and what can we do about it

  • Avoid comments

    Writing useful comments, when to write them and when not

  • Naming is hard

    How clear names make it easier to understand the code, and how to improve naming in our apps

  • Divide and conquer, or merge and relax

    Splitting code into functions and modules, when is the right time to introduce an abstraction, and when it’s better to wait

  • Don’t make me think

    All the different ways programmers like to write clever code, and why we should avoid it as much as possible

  • Code style

    Which code styles are actually improving readability and which are just opinions that don’t matter much

  • Lint your code

    How linters can help us maintain consistent and modern codebase, and promote some of the techniques discussed in the previous chapters

  • Autoformat your code

    How tools can make our lives much easier by formatting code for us

  • Learn your code editor

    Different techniques for editing code and customizing our environment to make our work more efficient and less tiring

  • Other techniques

    Make impossible states impossible

    Don’t try to predict the future

    Become a code scout

    Make the code greppable

    Avoid not invented here syndrome

    Avoid cargo cult programming

    Debug code with emojis

    Go for a walk or talk to a rubber duck

Artem Sapegin

About the author

Hola! I’m Artem.

I’m a software engineer with 20 years of experience in small startups and large corporations, like Wayfair, Mail.ru, Here Technologies, Omio, Stage+, and Badoo. I created React Styleguidist (a tool to create React components and share them with your team), among many other open source projects.

I’ve been blogging about frontend development for almost as many years. My favorite topics are component-driven development, testing, and accessibility.

Have a question?

Drop me a line at artem@sapegin.ru, @sapegin@mastodon.cloud, @iamsapegin, or open an issue.