Washing your code
$15.00
Minimum price
$20.00
Suggested price

Washing your code

A book on clean code for frontend developers

About the Book

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 a lot 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 examples in the book are written in JavaScript with a bit of TypeScript, React, CSS, and HTML.

  • Share this book

  • Categories

    • Computers and Programming
    • Software Engineering
    • JavaScript
  • Feedback

    Email the Author(s)
  • License

About the Author

Artem Sapegin
Artem Sapegin

Coffee first frontend engineer living in Berlin, award-losing photographer, and friend of dogs. Creator of React Styleguidist.

Table of Contents

    • Preface
    • Introduction
      • How to read this book
      • About code examples
      • Acknowledgments
    • Avoid loops
      • Replacing loops with array methods
      • Implied semantics of array methods
      • Chaining multiple operations
      • Dealing with side effects
      • Iterating over objects
      • Sometimes loops aren’t so bad
      • But aren’t array methods slow?
    • Avoid conditions
      • Unnecessary conditions
      • Optional function parameters
      • Processing arrays
      • Deduplicating algorithms
      • Early returns
      • Tables and maps
      • Negative conditions
      • Repeated conditions
      • Formulas
      • Nested ternaries
      • Complex conditions
    • Avoid reassigning variables
      • Don’t reuse variables
      • Incremental computations
      • Building complex objects
      • Avoid Pascal-style variables
      • Avoid temporary variables for function return values
      • Functions as the last resort
      • Indeterminate loops
      • TypeScript-related problems with reassignments
      • Help the brain with conventions
    • Avoid mutation
      • Avoid mutating operations
      • Beware of the mutating array methods
      • Avoid mutation of function parameters
      • Make the mutation explicit if it’s necessary
      • Updating objects
      • Sometimes mutation isn’t a villain
    • Avoid comments
      • Getting rid of comments (or not)
      • Good comments
      • Hack comments
      • Todo comments
      • Comments that reduce confusion
      • Comments with examples
      • Bad comments
    • Naming is hard
      • Name function parameters
      • Name complex conditions
      • Negative booleans are not not hard to read
      • The larger the scope, the longer the name
      • The shorter the scope, the better
      • Making magic numbers less magic
      • Not all numbers are magic
      • Group related constants
      • Abbreviations and acronyms
      • Prefixes and suffixes
      • Next and previous values
      • Beware of incorrect names
      • Beware of abstract and imprecise names
      • Use the A/HC/LC pattern
      • Use common terms
      • Use a single term for each concept
      • Prefer US English
      • Use common opposite pairs
      • Check the spelling of your names
      • Use established naming conventions
      • Avoid unnecessary variables
      • Avoiding name clashes
    • Divide and conquer, or merge and relax
      • Let abstractions grow
      • Size doesn’t always matter
      • Separate code that changes often
      • Keep together code that changes at the same time
      • Sweep that ugly code under the rug
      • Bless the inline refactoring!
      • Separate “what” and “how”
      • Avoid monster utility files
      • Avoid default exports
      • Avoid barrel files
      • Stay hydrated
    • Don’t make me think
      • Dark patterns of JavaScript
      • Gray areas
      • Make differences in code obvious
      • Avoid shortcuts
      • Write parallel code
    • Code style
      • Not all code styles are good
      • Obsolete code styles
      • Nonsensical code styles
      • Condition expansion
      • Range conditions
      • Readable numbers
      • Christmas trees against kebabs
      • Make it easy to remember and use
      • Sections, paragraphs, phrases…
      • A case for custom formatting
      • To semicolon or not
      • Tabs or spaces
      • The rest doesn’t matter
    • Other techniques
      • Make impossible states impossible
      • Don’t try to predict the future
      • Become a code scout
      • Write testable code
      • Write greppable code
      • Avoid not invented here syndrome
      • Avoid cargo cult programming
      • Debug code with emojis
      • Go for a walk or talk to a rubber duck
    • Lint your code
      • Code linting best practices
      • My top linter rules that should have never existed
      • Useful rules when used correctly
      • Linting legacy code
      • The ideal linting setup
      • Recommended ESLint plugins
      • Not just for JavaScript
    • Autoformat your code
      • Code formatting best practices
      • The ideal code formatting setup
      • Not just for JavaScript
    • Learn your code editor
      • Make it your own
      • File navigation
      • Code navigation
      • Hotkeys
      • Autosave
      • Multiple cursors
      • Tasks
      • Terminal
      • Source control
      • Documentation
      • Spell checking
      • Automated refactoring
      • Artificial intelligence
      • Plugins
      • Extras
    • Conclusion
    • Index of techniques and patterns
    • Index of code smells and antipatterns
    • Resources
      • Books
      • Articles
      • Talks
      • Please review the book
      • Got feedback?
      • Found an issue?
      • Follow me

The Leanpub 60 Day 100% Happiness Guarantee

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

Now, this is technically risky for us, since you'll have the book or course files either way. But we're so confident in our products and services, and in our authors and readers, that we're happy to offer a full money back guarantee for everything we sell.

You can only find out how good something is by trying it, and because of our 100% money back guarantee there's literally no risk to do so!

So, there's no reason not to click the Add to Cart button, is there?

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earnedover $13 millionwriting, publishing and selling on Leanpub.

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) and EPUB (for phones, tablets and 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 and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub