code quality practice and tools
DESCRIPTION
Why you should write quality code and how to effectively use tools to do it.TRANSCRIPT
![Page 1: Code Quality Practice and Tools](https://reader036.vdocuments.us/reader036/viewer/2022062418/55587601d8b42aaa7e8b5441/html5/thumbnails/1.jpg)
Code Quality
Paulin Solutions LLC
![Page 2: Code Quality Practice and Tools](https://reader036.vdocuments.us/reader036/viewer/2022062418/55587601d8b42aaa7e8b5441/html5/thumbnails/2.jpg)
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](https://reader036.vdocuments.us/reader036/viewer/2022062418/55587601d8b42aaa7e8b5441/html5/thumbnails/3.jpg)
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](https://reader036.vdocuments.us/reader036/viewer/2022062418/55587601d8b42aaa7e8b5441/html5/thumbnails/4.jpg)
Why Bother?
![Page 5: Code Quality Practice and Tools](https://reader036.vdocuments.us/reader036/viewer/2022062418/55587601d8b42aaa7e8b5441/html5/thumbnails/5.jpg)
What your client sees
![Page 6: Code Quality Practice and Tools](https://reader036.vdocuments.us/reader036/viewer/2022062418/55587601d8b42aaa7e8b5441/html5/thumbnails/6.jpg)
What you see
![Page 7: Code Quality Practice and Tools](https://reader036.vdocuments.us/reader036/viewer/2022062418/55587601d8b42aaa7e8b5441/html5/thumbnails/7.jpg)
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](https://reader036.vdocuments.us/reader036/viewer/2022062418/55587601d8b42aaa7e8b5441/html5/thumbnails/8.jpg)
Why would you do this to another Human Being!?!?
![Page 9: Code Quality Practice and Tools](https://reader036.vdocuments.us/reader036/viewer/2022062418/55587601d8b42aaa7e8b5441/html5/thumbnails/9.jpg)
What is Code Quality?
?
![Page 10: Code Quality Practice and Tools](https://reader036.vdocuments.us/reader036/viewer/2022062418/55587601d8b42aaa7e8b5441/html5/thumbnails/10.jpg)
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](https://reader036.vdocuments.us/reader036/viewer/2022062418/55587601d8b42aaa7e8b5441/html5/thumbnails/11.jpg)
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](https://reader036.vdocuments.us/reader036/viewer/2022062418/55587601d8b42aaa7e8b5441/html5/thumbnails/12.jpg)
Bad Code Smells!
![Page 13: Code Quality Practice and Tools](https://reader036.vdocuments.us/reader036/viewer/2022062418/55587601d8b42aaa7e8b5441/html5/thumbnails/13.jpg)
I've learned to live with the smell why else should I care?
![Page 14: Code Quality Practice and Tools](https://reader036.vdocuments.us/reader036/viewer/2022062418/55587601d8b42aaa7e8b5441/html5/thumbnails/14.jpg)
Reduce Bugs
![Page 15: Code Quality Practice and Tools](https://reader036.vdocuments.us/reader036/viewer/2022062418/55587601d8b42aaa7e8b5441/html5/thumbnails/15.jpg)
Lower Maintenance Effort
![Page 16: Code Quality Practice and Tools](https://reader036.vdocuments.us/reader036/viewer/2022062418/55587601d8b42aaa7e8b5441/html5/thumbnails/16.jpg)
It's Easier to Extend Good Code
![Page 17: Code Quality Practice and Tools](https://reader036.vdocuments.us/reader036/viewer/2022062418/55587601d8b42aaa7e8b5441/html5/thumbnails/17.jpg)
Create Good Code Karma
![Page 18: Code Quality Practice and Tools](https://reader036.vdocuments.us/reader036/viewer/2022062418/55587601d8b42aaa7e8b5441/html5/thumbnails/18.jpg)
Give your client the warm and fuzzy feeling.
Quality Code = Trust
![Page 19: Code Quality Practice and Tools](https://reader036.vdocuments.us/reader036/viewer/2022062418/55587601d8b42aaa7e8b5441/html5/thumbnails/19.jpg)
Components of Code Quality
![Page 20: Code Quality Practice and Tools](https://reader036.vdocuments.us/reader036/viewer/2022062418/55587601d8b42aaa7e8b5441/html5/thumbnails/20.jpg)
Good Code Should Work!
Functional/Non-Functional
![Page 21: Code Quality Practice and Tools](https://reader036.vdocuments.us/reader036/viewer/2022062418/55587601d8b42aaa7e8b5441/html5/thumbnails/21.jpg)
Components should be testable
![Page 22: Code Quality Practice and Tools](https://reader036.vdocuments.us/reader036/viewer/2022062418/55587601d8b42aaa7e8b5441/html5/thumbnails/22.jpg)
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](https://reader036.vdocuments.us/reader036/viewer/2022062418/55587601d8b42aaa7e8b5441/html5/thumbnails/23.jpg)
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](https://reader036.vdocuments.us/reader036/viewer/2022062418/55587601d8b42aaa7e8b5441/html5/thumbnails/24.jpg)
Rule of thumb for writing
testable code...
![Page 25: Code Quality Practice and Tools](https://reader036.vdocuments.us/reader036/viewer/2022062418/55587601d8b42aaa7e8b5441/html5/thumbnails/25.jpg)
Practice good design!
![Page 26: Code Quality Practice and Tools](https://reader036.vdocuments.us/reader036/viewer/2022062418/55587601d8b42aaa7e8b5441/html5/thumbnails/26.jpg)
Good code should be easy
to maintain
![Page 27: Code Quality Practice and Tools](https://reader036.vdocuments.us/reader036/viewer/2022062418/55587601d8b42aaa7e8b5441/html5/thumbnails/27.jpg)
Readable
![Page 28: Code Quality Practice and Tools](https://reader036.vdocuments.us/reader036/viewer/2022062418/55587601d8b42aaa7e8b5441/html5/thumbnails/28.jpg)
Stay DRY
![Page 29: Code Quality Practice and Tools](https://reader036.vdocuments.us/reader036/viewer/2022062418/55587601d8b42aaa7e8b5441/html5/thumbnails/29.jpg)
Avoid Excessive Complexity
![Page 30: Code Quality Practice and Tools](https://reader036.vdocuments.us/reader036/viewer/2022062418/55587601d8b42aaa7e8b5441/html5/thumbnails/30.jpg)
Ummmmmm that sounds like a lot of
work!
![Page 31: Code Quality Practice and Tools](https://reader036.vdocuments.us/reader036/viewer/2022062418/55587601d8b42aaa7e8b5441/html5/thumbnails/31.jpg)
Making sure it works
![Page 32: Code Quality Practice and Tools](https://reader036.vdocuments.us/reader036/viewer/2022062418/55587601d8b42aaa7e8b5441/html5/thumbnails/32.jpg)
Benefits of Functional Test Frameworks
Test often Self Documenting Code Fearlessly
![Page 33: Code Quality Practice and Tools](https://reader036.vdocuments.us/reader036/viewer/2022062418/55587601d8b42aaa7e8b5441/html5/thumbnails/33.jpg)
Making sure it's tested
• Cobertura• Emma• Clover• Jacoco• DevPartner
![Page 34: Code Quality Practice and Tools](https://reader036.vdocuments.us/reader036/viewer/2022062418/55587601d8b42aaa7e8b5441/html5/thumbnails/34.jpg)
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](https://reader036.vdocuments.us/reader036/viewer/2022062418/55587601d8b42aaa7e8b5441/html5/thumbnails/35.jpg)
Making sure it's maintainable
• PMD• FindBugs• DevPartner
![Page 36: Code Quality Practice and Tools](https://reader036.vdocuments.us/reader036/viewer/2022062418/55587601d8b42aaa7e8b5441/html5/thumbnails/36.jpg)
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](https://reader036.vdocuments.us/reader036/viewer/2022062418/55587601d8b42aaa7e8b5441/html5/thumbnails/37.jpg)
Putting it all together
![Page 38: Code Quality Practice and Tools](https://reader036.vdocuments.us/reader036/viewer/2022062418/55587601d8b42aaa7e8b5441/html5/thumbnails/38.jpg)
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](https://reader036.vdocuments.us/reader036/viewer/2022062418/55587601d8b42aaa7e8b5441/html5/thumbnails/39.jpg)
Parting thoughts
Don't write crappy code. I
know where you live.