decomposition and synthesis
- Code smells Jeff Atwood.
- etymology of refactoring
- The obvious answer comes from the notion of factoring in mathematics. You can take an expressions such as x2 + 5x + 6 and factor it into (x+2)(x+3). By factoring it you can make a number of mathematical operations much easier. Obviously this is much the same as representing 18 as 2*32.
improve internal structure, but don’t change the external behavior
list of refactors - slide 7 in http://www.slideshare.net/MarcusDenker/refactoring-1921411
code is written once, but read many times.
- Spaghetti code is a pejorative term for source code that has a complex and tangled control structure. It is named such because program flow tends to look like a bowl of spaghetti, i.e. twisted and tangled.
- long method
- large class
- long parameter list
temporary variable assigned more than once, but not a loop or collection
- push logic to the model -> conditional logic belongs in the model
- we’re going to push the nastiness down into the model. That way it can be tested and, so we can more easily change it in the future.
when you refactor, the first test is always create tests
Martin Fowler : “a change made to the internal structure of software to make it easier to understand and cheaper to modify without changing its observable behavior“.
William C. Wake : “Refactoring is the art of safely improving the design of existing code“.
The goal of refactoring is NOT to add new functionality. The goal is refactoring is to make code easier to maintain in the future. The process of refactoring involves the removal of duplication, the simplification of complex logic, and the clarification of unclear code.
refactoring versus rewriting
lego versus playdoh slide 9 http://www.slideshare.net/NeilGreen1/the-roi-of-refactoring-lego-vs-playdoh
Everything I need to know about refactoring I learned in kindergarden
“I’m not a great programmer; I’m just a good programmer with great habits.”- Kent Beck
Law of demeter?
Get into this?
- Inline class- http://www.refactoring.com/catalog/inlineClass.html
- Decompost conditional- http://www.refactoring.com/catalog/decomposeConditional.html
- Extract Class - http://www.refactoring.com/catalog/extractClass.html
- Inline Method
- Replace Conditional with Polymorphism
Replace Parameter with Method
extraction pattern- anti-pattern: http://blog.jayfields.com/2007/04/ruby-anti-pattern-extract-module-to.html
Refactoring: Even noobs know that refactoring is important. This presentation, inspired by Refactoring: Ruby Edition, will cover the whys, whens, and hows of refactoring using examples.