Washing your code
Minimum price
Suggested price

Washing your code

Write once, read seven times

About the Book

The purpose of this book is to show common code smells or patterns that often (but not always!) lead to poor code readability, and how you can refactor the code to make it more readable and maintainable. The book contains a lot of code examples, mostly based on real code with only minor adaptations.

Who is this book for

The book probably will be most useful for intermediate developers. If you’re a beginner, you probably have enough of other things to think about. If you have decades of experience, you probably can write a similar book yourself. This book is going to be opinionated, but you don’t have to agree with everything I’m saying, and that’s not the goal of the book. The goal is to show you one possible path, mine, and inspire to find your own. These techniques help me to write and review code every day, and I’ll be happy if you find some of them useful.

What you will learn

I’ll show code smells and patterns I often see during code reviews (and I review a lot of code every day!) and will walk you through the refactoring process to make code more readable and maintainable. I’ll also show when you shouldn’t follow my recommendations and keep using smelly code.

I’ll show you how to:

  • Replace loops with array methods.
  • Replace conditions with tables or remove them entirely.
  • Replace imperative code with declarative and separate “what” and “how.”
  • And more.

About the Author

Artem Sapegin
Artem Sapegin

Frontend developer living in Berlin, award-losing photographer and owner of two crazy dogs. Creator of React Styleguidist.

Table of Contents

  • Washing your code: Write once, read seven times
    • Preface
    • Acknowledgments
    • Avoid loops
    • Avoid conditions
    • Avoid reassigning variables
    • Avoid mutation
    • Avoid comments
    • Simplify, simplify, simplify
    • Naming is hard
    • Constants
    • Don’t surprise me
    • Separate “what” and “how”
    • Don’t waste energy (= save energy for important things)
    • Cargo cult programming
    • Don’t be clever
    • Divide and conquer, or merge and relax
    • Don’t make me think
    • Too many conventions
    • Make impossible states impossible
    • (Boy) scout rule
    • Greppable code
    • Size isn’t important
    • Don’t try to predict the future
    • Refactoring is inevitable
    • Not invented here syndrome
    • Code style
    • Code is evil
    • Tooling
    • Resources
    • Conclusion

The Leanpub 45-day 100% Happiness Guarantee

Within 45 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

See full terms

Do Well. Do Good.

Authors have earned$11,046,394writing, publishing and selling on Leanpub, earning 80% royalties while saving up to 25 million pounds of CO2 and up to 46,000 trees.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers), EPUB (for phones and tablets) and MOBI (for Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF, EPUB and/or MOBI files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub