code quality practice and tools

39
Code Quality Paulin Solutions LLC

Upload: bob-paulin

Post on 17-May-2015

631 views

Category:

Technology


5 download

DESCRIPTION

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

TRANSCRIPT

Page 1: Code Quality Practice and Tools

Code Quality

Paulin Solutions LLC

Page 2: Code Quality Practice and Tools

Paulin Solutions LLC

Have code will travel•Mobile Web Development•CMS/Portal (Liferay Adobe CQ 5.x)•Delivery Innovation

Page 3: Code Quality Practice and Tools

Topics

• Why bother writing quality code?• What is Code Quality• Components of Code Quality• Tools• Final Thoughts/Discussion

Page 4: Code Quality Practice and Tools

Why Bother?

Page 5: Code Quality Practice and Tools

What your client sees

Page 6: Code Quality Practice and Tools

What you see

Page 7: Code Quality Practice and Tools

The Psychology of Computer Programming

Gerald Weinberg

Programming is a social activity

CODE – It's not just for computers anymore!

Page 8: Code Quality Practice and Tools

Why would you do this to another Human Being!?!?

Page 9: Code Quality Practice and Tools

What is Code Quality?

?

Page 10: Code Quality Practice and Tools

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

}}}

Page 11: Code Quality Practice and Tools

Good or Badprotected 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.");

}

Page 12: Code Quality Practice and Tools

Bad Code Smells!

Page 13: Code Quality Practice and Tools

I've learned to live with the smell why else should I care?

Page 14: Code Quality Practice and Tools

Reduce Bugs

Page 15: Code Quality Practice and Tools

Lower Maintenance Effort

Page 16: Code Quality Practice and Tools

It's Easier to Extend Good Code

Page 17: Code Quality Practice and Tools

Create Good Code Karma

Page 18: Code Quality Practice and Tools

Give your client the warm and fuzzy feeling.

Quality Code = Trust

Page 19: Code Quality Practice and Tools

Components of Code Quality

Page 20: Code Quality Practice and Tools

Good Code Should Work!

Functional/Non-Functional

Page 21: Code Quality Practice and Tools

Components should be testable

Page 22: Code Quality Practice and Tools

Hard to Test

private 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);

}

Page 23: Code Quality Practice and Tools

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());

}

Page 24: Code Quality Practice and Tools

Rule of thumb for writing

testable code...

Page 25: Code Quality Practice and Tools

Practice good design!

Page 26: Code Quality Practice and Tools

Good code should be easy

to maintain

Page 27: Code Quality Practice and Tools

Readable

Page 28: Code Quality Practice and Tools

Stay DRY

Page 29: Code Quality Practice and Tools

Avoid Excessive Complexity

Page 30: Code Quality Practice and Tools

Ummmmmm that sounds like a lot of

work!

Page 31: Code Quality Practice and Tools

Making sure it works

Page 32: Code Quality Practice and Tools

Benefits of Functional Test Frameworks

Test often Self Documenting Code Fearlessly

Page 33: Code Quality Practice and Tools

Making sure it's tested

• Cobertura• Emma• Clover• Jacoco• DevPartner

Page 34: Code Quality Practice and Tools

Benefits of Code Coverage Tools

Know where your risk is Help with Debugging Determine what your QA is doing

Page 35: Code Quality Practice and Tools

Making sure it's maintainable

• PMD• FindBugs• DevPartner

Page 36: Code Quality Practice and Tools

Benefits of Static Analysis

Find bugs before you check in code Enforce Coding Standards Low effort code reviews

Page 37: Code Quality Practice and Tools

Putting it all together

Page 38: Code Quality Practice and Tools

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

Page 39: Code Quality Practice and Tools

Parting thoughts

Don't write crappy code. I

know where you live.