code quality assurance · code quality assurance (with a pinch of c# and php) peter kofler, ‘code...
TRANSCRIPT
Code Quality Assurance(with a pinch of C# and PHP)
Peter Kofler, ‘Code Cop’
SEQIS, April 2011
Agenda
• Presentation
–30’ “Theory”
–1h “Practice”
• Break
• Workshop (2h)
–Analysis of your Problems
–Discussion of Solutions
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
Peter Kofler
• Ph.D. (Appl. Math.)
• Professional SoftwareDeveloper for 11 years
• Lead Developer at System One
• “fanatic about code quality”
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
Zero-Defect Mindset(MSF)
Robert C. Martin(“Uncle Bob”)
SoftwareCraftsmanship
Craftsmanship
Engineering
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
CraftsmanshipOver Crap
Mindset
andPassion
Prime FactorsKata
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
... To Epic Evil
From Holy Bliss...
Don’tHurtMe!
The Requirements.
• Write a class named “PrimeFactors”that has one static method: Generate.
–The Generate method takes an integerargument and returns a List<int>.
–That list contains the prime factors innumerical sequence.
http://butunclebob.com/ArticleS.UncleBob.ThePrimeFactorsKata
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
Demo
Keep the bar green to keep the code clean
Unit Testing
• test individual units
• isolate each part
• show that the individual parts are
correct
• regression testing
• sort of living documentation
• executed within a frameworkhttp://en.wikipedia.org/wiki/Unit_testing
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
xUnit Frameworks
• e.g.
• Smalltalk - SUnit
• .NET - NUnit, MSTest
• Java - JUnit, TestNG
• PHP - PHPUnit
• C++, Groovy, Python, Ruby, Scala, etc.http://en.wikipedia.org/wiki/List_of_unit_testing_frameworks
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
TESTINGI FIND YOUR LACK OF TESTS DISTURBING.
Test-Driven Development
• add a test
• run all tests and see if the new one fails
• write some code
• run all tests and see them succeed
• refactor code
• „Red Green Refactor“http://en.wikipedia.org/wiki/Test_Driven_Development
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
A minute ago alltheir code worked
Testing isa mindset
Youhave to want it
Code Coverage
comprehensiveness of tests
Beware!
comprehensiveness ≠ quality!
Some Code Coverage Tools
• .NET - PartCover, (NCover, VS)
• Java - EMMA, Cobertura, Clover
• C++ - Covtool, gcov
• PHP - PHPUnit
• commercial products
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
Demo
Demo
Daily BuildsNightly Builds
ContinuousIntegration
Continuous Integration
• Maintain a code repository
• Automate the build
• Make the build self-testing
• Everyone commits every day
• Every commit should be built
• Keep the build fast
• Everyone can see the results of the buildhttp://en.wikipedia.org/wiki/Continuous_integration
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
Immediate Feedbackand
Early Warning
Some CI Servers
• .NET - TFS, CruiseControl.NET, Jenkins
• Java - CruiseControl, Jenkins
• C++ - Jenkins (Shell/Make)
• PHP - Hudson, phpUnderControl, Arbit
• commercial products - TeamCity, ALA
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
Good Enough?
Demo
Check What?
• Lexical analysis–naming, coding conventions, design idioms
• Flow/path analysis–null-pointer, dead code (conditional)
• Dependency analysis–architectural/design flaws
• Verification–mathematical proof of correctness
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
Some Static Analysis Tools
• .NET - FxCop, StyleCop (ReSharper)
• Java - Checkstyle, Findbugs, PMD
• C++ - (Sp)Lint
• PHP - PHPLint, PHP_CodeSniffer
• commercial products
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
Good Enough?
Demo
Some Code Review Tools
• Your peer (Pair Programming)
• Your version control system
• Your IDE (e.g. ReviewClipse)
• commercial products
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
ThankYou
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
www.code-cop.org
www.seqis.com
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
Links #1
Mindset
• http://codebetter.com/blogs/darrell.norton/archive/2003/12/03/4222.aspx (Zero-Defect Mindset)
• http://www.sqnz.org.nz/documents/ShipHappens/Software%20Quality%20Group%20Presentation_frame.htm (Zero-Defect Mindset)
• http://en.wikipedia.org/wiki/Fixing_Broken_Windows
• http://pragprog.com/the-pragmatic-programmer
Software Craftsmanship
• http://en.wikipedia.org/wiki/Robert_Cecil_Martin
• http://www.clean-code-developer.de/
• http://en.wikipedia.org/wiki/Software_craftsmanship
• http://vikashazrati.wordpress.com/2009/11/18/dissecting-software-craftsmanship/
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
Links #2
Kata
• http://butunclebob.com/ArticleS.UncleBob.ThePrimeFactorsKata
• http://en.wikipedia.org/wiki/Kata_(programming)
Katacasts C#
• http://blog.slatner.com/2009/11/11/PrimeFactorsKataInC.aspx
• http://urilavi.blogspot.com/2010/03/primes-kata.html
• http://www.rickardnilsson.net/post/2010/07/21/Prime-Factors-Kata.aspx
• http://blog.softwareontheside.com/2011/03/prime-factors-kata-in-c.html
Unit Test
• http://en.wikipedia.org/wiki/Unit_testing
• http://en.wikipedia.org/wiki/Xunit
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
Links #3
• http://en.wikipedia.org/wiki/List_of_unit_testing_frameworks
TDD
• http://en.wikipedia.org/wiki/Test_Driven_Development
Code Coverage
• http://en.wikipedia.org/wiki/Code_coverage
Continuous Integration
• http://jenkins-ci.org/
• http://www.codinghorror.com/blog/archives/000818.html
• http://www.stevemcconnell.com/ieeesoftware/bp04.htm
• http://www.joelonsoftware.com/articles/fog0000000023.html
• http://en.wikipedia.org/wiki/Continuous_integration
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
Links #4
Static Code Analysis
• http://en.wikipedia.org/wiki/Static_code_analysis
• http://en.wikipedia.org/wiki/List_of_tools_for_static_code_analysis
Code Review
• http://en.wikipedia.org/wiki/Code_review
• http://en.wikipedia.org/wiki/Pair_programming
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
CC Images #1
• demo: http://www.flickr.com/photos/st3f4n/4109940538/
• list: http://www.flickr.com/photos/kylesteeddesign/3724074594/
• spray face: http://www.flickr.com/photos/iangallagher/4115047191/
• eggs: http://www.flickr.com/photos/nickwheeleroz/2475011402/
• windows: http://www.flickr.com/photos/sketchglass/4281424410/
• shoe maker: http://www.flickr.com/photos/tbatty/1450209613/
• factory: http://www.flickr.com/photos/94693506@N00/4643248587/
• passion: http://gapingvoid.com/2011/03/29/suddenly-passion/
• grail: http://www.flickr.com/photos/mr_t_in_dc/4183854194/
• evil: http://www.flickr.com/photos/legofenris/4476593087/
• puppy: http://www.flickr.com/photos/davdunc/3706558237/
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
CC Images #2
• fence: http://www.flickr.com/photos/30830597@N08/3630649274/
• Darth Vader: http://rubystammtisch.at/
• covered car: http://www.flickr.com/photos/paulk/3166328163/
• works: http://www.codinghorror.com/blog/archives/000818.html
• Agnes: http://www.youbrokethebuild.com/
• microscope: http://www.flickr.com/photos/gonzales2010/8632116/
• review: http://www.flickr.com/photos/smitty/2245445147/
• questions: http://www.flickr.com/photos/seandreilinger/2326448445/
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY