code quality assurance
Post on 08-Jun-2015
Embed Size (px)
DESCRIPTIONDo's and don'ts regarding Code Quality Assurance. Presentation given to a technical Java audience.
- 1. CODE QUALITY ASSURANCEJan 15, 2013Bart Blommaerts firstname.lastname@example.org EMEA NG Java & WEB: HP Belgium2010 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice
2. Agenda Why do we need clean code?What is clean code?How do we write clean code?How do we test clean code?How do we measure clean code?Disclaimer: clean code vs. great codeQ&A2HP ConfidentialJan 2013 3. Why do we need clean code?3HP ConfidentialJan 2013 4. Why do we need clean code? Objectives Easyto read and understand Unnecessary Maintaining and extending code is easierFirst step towards re-use! Project code and noise are removedlifecycle cost will be reducedCost of owning a mess ..Writing clean code is what you must do in order to call yourself a professional. There is no reasonable excuse for doing anything less than your best.Robert C. Martin4HP ConfidentialJan 2013 5. What is clean code? 5HP ConfidentialSimple and direct Human readable Efficient No duplications: DRY Made for the problem Easy to enhanceJan 2013 6. How do we write clean code? SRP: Single responsibility principle Stepdown RuleDo One ThingRestrict number of arguments (3 is a lot ..)Boy Scout Rule 6Leave code better than you found it Dont comment bad code, rewrite itHP ConfidentialJan 2013 7. How do we write clean code? Meaningful, self-explaining names Purpose of a variable, class, method, .. Avoid disinformation (eg. lblUserName)Error Handling 7Dont return nullUse exceptions rather then return codes Dont pass nullExpresses intentHP ConfidentialJan 2013 8. How do we test clean code? SRP: Single responsibility principle Boy Scout Rule 8Unit test enablerAdd unit tests before refactoringHP ConfidentialJan 2013 9. How do we test clean code? Meaningful names Understand what to testError Handling @Test(expected=CleanCodeException.class)Fix a bug only once. Write Unit tests when fixing bugs!9HP ConfidentialJan 2013 10. How do we measure clean code? Sonar integration http://sonar.elabs.eds.com:9000/Maven: jdbc:mysql://sonar.elabs.eds.com:3306/sonar?useUnicode=true&characterEncoding=utf8 com.mysql.jdbc.Driverxxhttp://sonar.elabs.eds.com:900010HP ConfidentialJan 2013 11. How do we measure clean code? Ant: 11HP ConfidentialJan 2013 12. How do we measure clean code? 12Demo!HP ConfidentialJan 2013 13. Disclaimer: clean code vs. great code Primary goal: making it workSRP But: no methods with 1 line of codeBut: dont write a huge amount of tiny classesBoy Scout Rule 13Dont go overboardHP ConfidentialJan 2013 14. Q& Ahttp://www.osnews.com/comics 14HP ConfidentialJan 2013 15. THANKS FOR YOUR ATTENTION2010 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice