90 likes | 210 Views
XP2007b Extreme Code Quality. Dongsu Park Venkatesh BS. Agenda. What is “Extreme Code Quality”? How to do it in XP. Example. Remember. What is Extreme Code Quality?. Code Quality: Amount of flexibility in the code. Flexibility: change, adapt and re-use.
E N D
XP2007bExtreme Code Quality Dongsu Park Venkatesh BS
Agenda • What is “Extreme Code Quality”? • How to do it in XP. • Example. • Remember.
What is Extreme Code Quality? • Code Quality: Amount of flexibility in the code. • Flexibility: change, adapt and re-use. • Extreme : To the maximum possible via XP paradigm. • Why? • Because of humans. • Misunderstand communications. • Requirements change. • Examples*: • @2% per month (software industry requirement change). • 30% of rework due to mistakes (building construction). • “Soft”ware – easy to change: how well, how fast, how cheap. To get a good design. * Source: IEEE Software, May 2004; Andy Hunt and Dave Thomas
How to do it in XP? • Test everything. • Code should be testable. • Write tests together with code. • Keep it DRY / Eliminate Duplication. • Don’t Repeat Yourself: Code (Documents, Review, Processes) • Duplication is harder to read (time consuming and redundant reading), understand and maintain. • Keep it Shy • Highly modular, highly cohesive and loosely coupled. • Static, Dynamic, Domain and Temporal couplings. • Tell the other guy. • Tell, don’t ask (OO Principle: not as Function -> as Message!). • Let the code reflect your intentions. Tools: Refactoring. DRY: Do not Repeat Yourself.
Actions Logic Actions Logic Example. • Test everything. • Finite State Machine. • Keep it DRY / Eliminate Duplication. • Extract Superclass
Example…cont. • Minimize entities. • Extract class • Express all ideas. • Introduce explaining variable. if ( (platform.toUpperCase().indexOf("MAC") > -1) && (browser.toUpperCase().indexOf("IE") > -1) && wasInitialized() && resize > 0 ) { // do something } final boolean isMacOs = platform.toUpperCase().indexOf("MAC") > -1; final boolean isIEBrowser = browser.toUpperCase().indexOf("IE") > -1; final boolean wasResized = resize > 0; if (isMacOs && isIEBrowser && wasInitialized() && wasResized) { // do something }
Remember • Keep it DRY, Keep it Shy and Tell the other guy. • Test everything, Eliminate duplication, Minimize entities and Express all ideas. • Extreme code quality is important. • Apply the principles and review (daily/weekly). • Allocate time in your planning. • It looks subjective – so understand and practice ! • Past eXP: Everyone knew refactoring but was not applied. It’s a challenge for us to apply …
Fragen? danke für Ihnen Aufmerksamkeit
References • http://www.pragmaticprogrammer.com/ • http://www.xprogramming.com/xpmag/expEmergentDesign.htm • http://www.extremeprogramming.org/ • http://www.xprogramming.com/ • Agile Software Development, Principles, Patterns and Practices; Robert C. Martin • Previous XP Lab presentations; XP2007a