Your SlideShare is downloading. ×
0
Code Quality Assurance
Code Quality Assurance
Code Quality Assurance
Code Quality Assurance
Code Quality Assurance
Code Quality Assurance
Code Quality Assurance
Code Quality Assurance
Code Quality Assurance
Code Quality Assurance
Code Quality Assurance
Code Quality Assurance
Code Quality Assurance
Code Quality Assurance
Code Quality Assurance
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Code Quality Assurance

118

Published on

Do's and don'ts regarding Code Quality Assurance. Presentation given to a technical Java audience.

Do's and don'ts regarding Code Quality Assurance. Presentation given to a technical Java audience.

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
118
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. CODE QUALITY ASSURANCE Jan 15, 2013 Bart Blommaerts bart.blommaerts@hp.com EMEA NG Java & WEB: HP Belgium ©2010 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 code • Q&A 2 HP Confidential Jan 2013
  • 3. Why do we need clean code? 3 HP Confidential Jan 2013
  • 4. Why do we need clean code? Objectives – Easy to read and understand – Unnecessary – Maintaining • and extending code is easier First step towards re-use! – Project • code and noise are removed lifecycle cost will be reduced Cost 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. Martin 4 HP Confidential Jan 2013
  • 5. What is clean code? • • • • • • 5 HP Confidential Simple and direct Human readable Efficient No duplications: DRY Made for the problem Easy to enhance Jan 2013
  • 6. How do we write clean code? • SRP: Single responsibility principle – – Stepdown Rule – • Do One Thing Restrict number of arguments (3 is a lot ..) Boy Scout Rule – – 6 Leave code better than you found it Don’t comment bad code, rewrite it HP Confidential Jan 2013
  • 7. How do we write clean code? • Meaningful, self-explaining names – – • Purpose of a variable, class, method, .. Avoid disinformation (eg. lblUserName) Error Handling – – 7 Don’t return null – • Use exceptions rather then return codes Don’t pass null Expresses intent HP Confidential Jan 2013
  • 8. How do we test clean code? • SRP: Single responsibility principle – • Boy Scout Rule – 8 Unit test enabler Add unit tests before refactoring HP Confidential Jan 2013
  • 9. How do we test clean code? • Meaningful names – • Understand what to test Error Handling – @Test(expected=CleanCodeException.class) Fix a bug only once. Write Unit tests when fixing bugs! 9 HP Confidential Jan 2013
  • 10. How do we measure clean code? • Sonar integration – • http://sonar.elabs.eds.com:9000/ Maven: <properties> <sonar.jdbc.url> jdbc:mysql://sonar.elabs.eds.com:3306/sonar?useUnicode=true&amp;characterEncoding=utf8 </sonar.jdbc.url> <sonar.jdbc.driver>com.mysql.jdbc.Driver</sonar.jdbc.driver> <sonar.jdbc.username>x</sonar.jdbc.username> <sonar.jdbc.password>x</sonar.jdbc.password> <sonar.host.url>http://sonar.elabs.eds.com:9000</sonar.host.url> </properties> 10 HP Confidential Jan 2013
  • 11. How do we measure clean code? • Ant: <!-- Sonar properties --> <property name="sonar.jdbc.url" value="jdbc:mysql://sonar.elabs.eds.com:3306/sonar?useUnicode=true&amp;characterEncoding=utf8" /> <property name="sonar.jdbc.driverClassName" value="com.mysql.jdbc.Driver" /> <property name="sonar.jdbc.username" value="x" /> <property name="sonar.jdbc.password" value="x" /> <property name="sonar.host.url" value="http://sonar.elabs.eds.com:9000" /> <!-- Sonar target --> <target name="sonar" depends="compile"> <sonar:sonar workDir="." key="be.vlaanderen.vip:xfire" version="02.00" xmlns:sonar="antlib:org.sonar.ant"> <sources> <path location="${project.dir.src}" /> </sources> </sonar:sonar> </target> <!-- Sonar task --> <taskdef uri="antlib:org.sonar.ant" resource="org/sonar/ant/antlib.xml"> <classpath> <fileset dir="${project.dir.lib}"> <include name="sonar-ant-task-1.0.jar" /> </fileset> </classpath> </taskdef> 11 HP Confidential Jan 2013
  • 12. How do we measure clean code? • 12 Demo! HP Confidential Jan 2013
  • 13. Disclaimer: clean code vs. great code • Primary goal: making it work • SRP – – • But: no methods with 1 line of code But: don’t write a huge amount of tiny classes Boy Scout Rule – 13 Don’t go overboard HP Confidential Jan 2013
  • 14. Q& A http://www.osnews.com/comics 14 HP Confidential Jan 2013
  • 15. THANKS FOR YOUR ATTENTION ©2010 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice

×