fight the rot - refactor stinky javascript

30
Fight the Rot Refactor stinky JavaScript @damienklinnert Donnerstag, 18. Juli 13

Upload: damien-klinnert

Post on 06-May-2015

291 views

Category:

Technology


2 download

DESCRIPTION

Is you node.js application hard to maintain? Is your buglist growing while the list of deployable features shrinks? Is bad code slowing you down? Then the rot has taken over and you are probably afraid of touching your code. I will show you how to start refactoring, when there are no tests around, no documentation exists, and architecture is hard to understand. Covering strategy, unit tests, documentation, measuring progress, tools, best practices and things to avoid.

TRANSCRIPT

Page 1: Fight the Rot - Refactor stinky JavaScript

Fight the RotRefactor stinky JavaScript

@damienklinnertDonnerstag, 18. Juli 13

Page 2: Fight the Rot - Refactor stinky JavaScript

a typical day?

• Mr. Wheatley, owner of Copy+Paste Inc., asks for a (simple) change in his web store

• backstage passes should rise by 3 points in quality, if there are less than 6 days to event

Donnerstag, 18. Juli 13

Page 3: Fight the Rot - Refactor stinky JavaScript

Donnerstag, 18. Juli 13

Page 4: Fight the Rot - Refactor stinky JavaScript

WAAAAAT???Donnerstag, 18. Juli 13

Page 5: Fight the Rot - Refactor stinky JavaScript

Donnerstag, 18. Juli 13

Page 6: Fight the Rot - Refactor stinky JavaScript

the hacky way ™

Donnerstag, 18. Juli 13

Page 7: Fight the Rot - Refactor stinky JavaScript

Donnerstag, 18. Juli 13

Page 8: Fight the Rot - Refactor stinky JavaScript

Donnerstag, 18. Juli 13

Page 9: Fight the Rot - Refactor stinky JavaScript

done!(?)git add * && git commit && git push

Donnerstag, 18. Juli 13

Page 10: Fight the Rot - Refactor stinky JavaScript

6 minutes passed now

Donnerstag, 18. Juli 13

Page 11: Fight the Rot - Refactor stinky JavaScript

Refactoring

Donnerstag, 18. Juli 13

Page 12: Fight the Rot - Refactor stinky JavaScript

Donnerstag, 18. Juli 13

Page 13: Fight the Rot - Refactor stinky JavaScript

Donnerstag, 18. Juli 13

Page 14: Fight the Rot - Refactor stinky JavaScript

Donnerstag, 18. Juli 13

Page 15: Fight the Rot - Refactor stinky JavaScript

Donnerstag, 18. Juli 13

Page 16: Fight the Rot - Refactor stinky JavaScript

Donnerstag, 18. Juli 13

Page 17: Fight the Rot - Refactor stinky JavaScript

Donnerstag, 18. Juli 13

Page 18: Fight the Rot - Refactor stinky JavaScript

Donnerstag, 18. Juli 13

Page 19: Fight the Rot - Refactor stinky JavaScript

step by step tut

Donnerstag, 18. Juli 13

Page 20: Fight the Rot - Refactor stinky JavaScript

done!(?)git add * && git commit && git push

Donnerstag, 18. Juli 13

Page 21: Fight the Rot - Refactor stinky JavaScript

refactoring is disciplined technique for restructuring an existing body of code, altering its internal structure without

changing its external behavior

Donnerstag, 18. Juli 13

Page 22: Fight the Rot - Refactor stinky JavaScript

refactoring

• break dependencies

• bring system under tests

• refactor

• add feature

• measure code quality

Donnerstag, 18. Juli 13

Page 23: Fight the Rot - Refactor stinky JavaScript

break dependencies

• factories, abstract factories

• dependency injection knit.js

• pass as parameter

Donnerstag, 18. Juli 13

Page 24: Fight the Rot - Refactor stinky JavaScript

add tests

• mocha, karma.js

• instrument with istanbul, js-coverage

• test current behavior, not expected

Donnerstag, 18. Juli 13

Page 25: Fight the Rot - Refactor stinky JavaScript

refactor

• few good tools around for js

• pair programming

tools sublime plugin, no really tools

Donnerstag, 18. Juli 13

Page 26: Fight the Rot - Refactor stinky JavaScript

add feature

• design patterns

Donnerstag, 18. Juli 13

Page 27: Fight the Rot - Refactor stinky JavaScript

measure code quality

• plato.js

• jscomplexity

• node-madge

Donnerstag, 18. Juli 13

Page 28: Fight the Rot - Refactor stinky JavaScript

clean code

• everything is pretty much what you expect

• documented

• as if by one and the same author

• following your style guide

Donnerstag, 18. Juli 13

Page 29: Fight the Rot - Refactor stinky JavaScript

bad code

• detect with jsmeter

• or jshint complexity settings

• not linted

• not tested

• complex

Donnerstag, 18. Juli 13

Page 30: Fight the Rot - Refactor stinky JavaScript

thank you!

follow me on twitter @damienklinnert

Donnerstag, 18. Juli 13