JS Minty Fresh

Identifying & Eliminating JavaScript Code Smells

Rebecca Murphey

bazaarvoice

[@rmurphey](http://twitter.com/rmurphey)  ☆  [rmurphey.com](http://rmurphey.com) [bazaarvoice.com](http://bazaarvoice.com)
## what’s that smell? code smells are easy to spot,
but **suggestive of a deeper problem**
## what’s the harm? - debugging is harder - maintainability suffers - features are harder to add
### smells beget smells.
### smells obscure opportunity.

The Smell: Repetitive Code

The Fix: A Function

smelly

minty

opportunity

The Smell: Repetitive Code

The Fix: Objects

smelly

minty

opportunity

The Smell: Unnecessary IDs

The Fix: Closures

smelly

minty

The Smell: Complex Functions

The Fix: More & Smaller Functions

smelly

minty

opportunity

The Smell:
Async Acrobatics

The Fix: Deferreds

smelly

minty

opportunity

The Smell: HTML
in Your JavaScript

The Fix: Templates

smelly

minty

opportunity

### minty code opens the door to abstractions.
## demand minty code, from yourself & others - eliminate repetition - keep functions short and simple - avoid complex if / else logic - manage and leverage asynchronicity - keep HTML out of your JS

[moar smells](http://en.wikipedia.org/wiki/Code_smells)
### it will make you
a better developer.
## work at getting better - read libraries & examples - rewrite code from IRC, StackOverflow - incorporate code reviews into your workflow - maintain and enforce a style guide on projects - write tests for your code
**Repo** [github.com/rmurphey/js-minty-fresh](https://github.com/rmurphey/js-minty-fresh) **Links** [pinboard.in/u:rmurphey/t:js-minty-fresh](http://pinboard.in/u:rmurphey/t:js-minty-fresh) **Presentation** [rmurphey.com/js-minty-fresh/presentation/](http://rmurphey.com/js-minty-fresh/presentation/)

bazaarvoice

[@rmurphey](http://twitter.com/rmurphey)  ☆  [rmurphey.com](http://rmurphey.com) [bazaarvoice.com](http://bazaarvoice.com)