Washing your code
This book is 40% complete
Last updated on 2020-03-25
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.
Washing your code: Write once, read seven times
- Avoid loops
- Avoid conditions
- Avoid reassigning variables
- Avoid mutation
- Avoid comments
- Simplify, simplify, simplify
- Naming is hard
- 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
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
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.