Code Quality Practice and Tools

967 views

Published on

Why you should write quality code and how to effectively use tools to do it.

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
967
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
20
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • So often people look at this as an oxymoron. As long as it works isn't that enough. Well those of us that have been doing this long enough know there's more to delivery than just getting the code to work. We all seemed to know what bad code looks like but what about good code. It's harder to nail down a generic definition that's useful in all cases but we will try anyways.
  • Long Methods Tight Coupling Concrete Implementation Excessive Code Branching
  • Short Methods Loose Coupling Abstract Implementation Minimal Code Branching
  • Code Quality Practice and Tools

    1. 1. Code Quality Paulin Solutions LLC
    2. 2. Paulin Solutions LLC <ul><li>Have code will travel </li></ul><ul><li>Mobile Web Development </li></ul><ul><li>CMS/Portal (Liferay Adobe CQ 5.x) </li></ul><ul><li>Delivery Innovation </li></ul>
    3. 3. Topics <ul><li>Why bother writing quality code? </li></ul><ul><li>What is Code Quality </li></ul><ul><li>Components of Code Quality </li></ul><ul><li>Tools </li></ul><ul><li>Final Thoughts/Discussion </li></ul>
    4. 4. Why Bother?
    5. 5. What your client sees
    6. 6. What you see
    7. 7. The Psychology of Computer Programming <ul><li>Gerald Weinberg </li></ul><ul><li>Programming is a social activity </li></ul><ul><li>CODE – It's not just for computers anymore! </li></ul>
    8. 8. Why would you do this to another Human Being!?!?
    9. 9. What is Code Quality? <ul><li>? </li></ul>
    10. 10. Good or Bad? protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { if (req != null ) { if (req.getParameter( &quot;type&quot; ) != null ) { String reqType = req.getParameter( &quot;type&quot; ); if (reqType == &quot;FOO&quot; ) //Do something }}}
    11. 11. Good or Bad protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String type = req.getParameter( &quot;type&quot; ); if ( FORWARD_TYPE .equalsIgnoreCase(type)) { countForward(req, resp); } else if ( BACKWARD_TYPE .equalsIgnoreCase(type)) { countBackwards(req, resp); } else { throw new RuntimeException( &quot;This type is not supported.&quot; ); }
    12. 12. Bad Code Smells!
    13. 13. I've learned to live with the smell why else should I care?
    14. 14. Reduce Bugs
    15. 15. Lower Maintenance Effort
    16. 16. It's Easier to Extend Good Code
    17. 17. Create Good Code Karma
    18. 18. Give your client the warm and fuzzy feeling. Quality Code = Trust
    19. 19. Components of Code Quality
    20. 20. Good Code Should Work! Functional/Non-Functional
    21. 21. Components should be testable
    22. 22. Hard to Test <ul><li>p rivate void addPlayerObjects() </li></ul><ul><li>/* the physical objects are the enclosing box and its spheres */ </li></ul><ul><li>{ </li></ul><ul><li>// create the spheres </li></ul><ul><li>players = new PlayerManager(sceneBG, world, collSpace, BLUE, RED); </li></ul><ul><li>// need to add DLL files ElementXML.dll, Java_sml_ClientInterface.dll, </li></ul><ul><li>// and SoarKernalSML.dll to java.library.path </li></ul><ul><li>IFormation offFormation = new FndtFormation( </li></ul><ul><li>PlayerManager.OFF_PLAYER_TYPE); </li></ul><ul><li>IFormation defFormation = new FndtFormation( </li></ul><ul><li>PlayerManager.DEF_PLAYER_TYPE); </li></ul><ul><li>InitFootballAgents initTask = new InitFootballAgents(positions, </li></ul><ul><li>offFormation, defFormation); </li></ul><ul><li>FormationSoarTask task = new FormationSoarTask(playText, offFormation, </li></ul><ul><li>defFormation); </li></ul><ul><li>try </li></ul><ul><li>{ </li></ul><ul><li>soarManager.clearAgents(); </li></ul><ul><li>soarManager.executeSoarTask(initTask); </li></ul><ul><li>soarManager.executeSoarTask(task); </li></ul><ul><li>} catch (Exception e) </li></ul><ul><li>{ </li></ul><ul><li>e.printStackTrace(); </li></ul><ul><li>JOptionPane.showMessageDialog( this , e.getMessage(), &quot;Soar Error&quot; , </li></ul><ul><li>JOptionPane.ERROR_MESSAGE); </li></ul><ul><li>} </li></ul>
    23. 23. Easy to test <ul><li>public ModelAndView welcome(HttpServletRequest request, </li></ul><ul><li>HttpServletResponse response) throws Exception { </li></ul><ul><li>return new ModelAndView( &quot;welcome.page&quot; , &quot;data&quot; , dataManager ); </li></ul><ul><li>} </li></ul><ul><li>public ModelAndView openMenu(HttpServletRequest request, </li></ul><ul><li>HttpServletResponse response) throws Exception { </li></ul><ul><li>return new ModelAndView( &quot;topNav.comp&quot; , &quot;data&quot; , dataManager ); </li></ul><ul><li>} </li></ul><ul><li>public ModelAndView manageUsers(HttpServletRequest request, </li></ul><ul><li>HttpServletResponse response) throws Exception { </li></ul><ul><li>return new ModelAndView( &quot;manageusers.page&quot; , &quot;userList&quot; , dietDaoService .getUsers()); </li></ul><ul><li>} </li></ul>
    24. 24. Rule of thumb for writing testable code...
    25. 25. Practice good design!
    26. 26. Good code should be easy to maintain
    27. 27. Readable
    28. 28. Stay DRY
    29. 29. Avoid Excessive Complexity
    30. 30. Ummmmmm that sounds like a lot of work!
    31. 31. Making sure it works
    32. 32. Benefits of Functional Test Frameworks <ul><li>Test often </li></ul><ul><li>Self Documenting </li></ul><ul><li>Code Fearlessly </li></ul>
    33. 33. Making sure it's tested <ul><li>Cobertura </li></ul><ul><li>Emma </li></ul><ul><li>Clover </li></ul><ul><li>Jacoco </li></ul><ul><li>DevPartner </li></ul>
    34. 34. Benefits of Code Coverage Tools <ul><li>Know where your risk is </li></ul><ul><li>Help with Debugging </li></ul><ul><li>Determine what your QA is doing </li></ul>
    35. 35. Making sure it's maintainable <ul><li>PMD </li></ul><ul><li>FindBugs </li></ul><ul><li>DevPartner </li></ul>
    36. 36. Benefits of Static Analysis <ul><li>Find bugs before you check in code </li></ul><ul><li>Enforce Coding Standards </li></ul><ul><li>Low effort code reviews </li></ul>
    37. 37. Putting it all together
    38. 38. Benefits of Sonar <ul><li>Single Dashboard to display test results, coverage, static analysis. </li></ul><ul><li>Drill down into the code with syntax highlighting </li></ul><ul><li>Issue Assignment and workflow </li></ul><ul><li>Simple build integration </li></ul>
    39. 39. Parting thoughts Don't write crappy code. I know where you live.

    ×