Code Quality Practice and Tools
Upcoming SlideShare
Loading in...5
×
 

Code Quality Practice and Tools

on

  • 830 views

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

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

Statistics

Views

Total Views
830
Views on SlideShare
830
Embed Views
0

Actions

Likes
0
Downloads
17
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • 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 Code Quality Practice and Tools Presentation Transcript

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