refactotum #6 2g experiencerefactor |rē㷦faktər| verb to improve a program’s readability or...

39
2G Experience Published under the Creative Commons Attribution Noncommercial Share Alike License Version 2.5. (Please see http://creativecommons.org/licenses/by-nc-sa/2.5 for complete details.) Refactotum #6 Jason Rudolph [email protected]

Upload: others

Post on 01-Aug-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Refactotum #6 2G Experiencerefactor |rē㷦faktər| verb to improve a program’s readability or simplify its structure without changing its results; sometimes informally referred

2G Experience

Published under the Creative Commons Attribution Noncommercial Share Alike License Version 2.5. (Please see http://creativecommons.org/licenses/by-nc-sa/2.5 for complete details.)

Refactotum #6Jason Rudolph

[email protected]

Page 2: Refactotum #6 2G Experiencerefactor |rē㷦faktər| verb to improve a program’s readability or simplify its structure without changing its results; sometimes informally referred

Introduction

Jason Rudolph

jasonrudolph.com

thinkrelevance.com

Page 3: Refactotum #6 2G Experiencerefactor |rē㷦faktər| verb to improve a program’s readability or simplify its structure without changing its results; sometimes informally referred

refactor |rēˈfaktər|verbto improve a program’s readability or simplify its structure without changing its results; sometimes informally referred to as "cleaning it up"

http://en.wikipedia.org/wiki/refactor

Page 4: Refactotum #6 2G Experiencerefactor |rē㷦faktər| verb to improve a program’s readability or simplify its structure without changing its results; sometimes informally referred

factotum |fakˈtōtəm|noun ( pl. -tums )a person having many diverse activities or responsibilities : he was employed as the general factotum.

http://www.encyclopedia.com/doc/1O999-factotum.html

Page 5: Refactotum #6 2G Experiencerefactor |rē㷦faktər| verb to improve a program’s readability or simplify its structure without changing its results; sometimes informally referred

How to be a Refactotum

1. Set aside four hours

2. Choose an open source project

3. Get edge

4. Get metrics

5. Analyze

6. Contribute

7. Submit

Page 6: Refactotum #6 2G Experiencerefactor |rē㷦faktər| verb to improve a program’s readability or simplify its structure without changing its results; sometimes informally referred

Refactotum History

Typo - eRubyCon 2007

JRuby - No Fluff, Just Stuff

ActiveRecord

YUIDomCollapse - The Ajax Experience 2007

Rake - RubyConf 2007

Grails - 2G Experience

Page 7: Refactotum #6 2G Experiencerefactor |rē㷦faktər| verb to improve a program’s readability or simplify its structure without changing its results; sometimes informally referred

If this is your first night at Refactotum, you have to refactor. -- Graeme Rocher as Tyler Durden, Fight Club (almost)

Page 8: Refactotum #6 2G Experiencerefactor |rē㷦faktər| verb to improve a program’s readability or simplify its structure without changing its results; sometimes informally referred

Up and Running with Grails Source

Go to grails.org/installation

Get the SVN bits

Verify tests pass

ant test

Use Cobertura to hunt for suspicious code

ant test-with-coverage

Page 9: Refactotum #6 2G Experiencerefactor |rē㷦faktər| verb to improve a program’s readability or simplify its structure without changing its results; sometimes informally referred

Build Noise

[groovyc] .../grails/src/web/org/codehaus/groovy/grails/web/ servlet/mvc/GrailsHttpSession.java:21: warning: [deprecation] javax.servlet.http.HttpSessionContext in javax.servlet.http has been deprecated[groovyc] import javax.servlet.http.HttpSessionContext;[groovyc] ^...[groovyc] .../grails/src/commons/org/codehaus/groovy/grails/ commons/DefaultGrailsDomainClassProperty.java:487: warning: [deprecation] getPersistantProperties() in org.codehaus.groovy.grails.commons.GrailsDomainClass has been deprecated[groovyc] public GrailsDomainClassProperty[] getPersistantProperties() [groovyc] ^...[groovyc] 3 warnings...[groovyc] 6 warnings

Page 10: Refactotum #6 2G Experiencerefactor |rē㷦faktər| verb to improve a program’s readability or simplify its structure without changing its results; sometimes informally referred

ShhhhhDemo

Page 11: Refactotum #6 2G Experiencerefactor |rē㷦faktər| verb to improve a program’s readability or simplify its structure without changing its results; sometimes informally referred

Are You Covered?

Page 12: Refactotum #6 2G Experiencerefactor |rē㷦faktər| verb to improve a program’s readability or simplify its structure without changing its results; sometimes informally referred

Shouldn’t This Do the Trick?

Page 13: Refactotum #6 2G Experiencerefactor |rē㷦faktər| verb to improve a program’s readability or simplify its structure without changing its results; sometimes informally referred

What Gives?

Page 14: Refactotum #6 2G Experiencerefactor |rē㷦faktər| verb to improve a program’s readability or simplify its structure without changing its results; sometimes informally referred

Testing. Testing. Is This Thing On?

Page 15: Refactotum #6 2G Experiencerefactor |rē㷦faktər| verb to improve a program’s readability or simplify its structure without changing its results; sometimes informally referred

Being Inclusive

Page 16: Refactotum #6 2G Experiencerefactor |rē㷦faktər| verb to improve a program’s readability or simplify its structure without changing its results; sometimes informally referred

Going Green

Page 17: Refactotum #6 2G Experiencerefactor |rē㷦faktər| verb to improve a program’s readability or simplify its structure without changing its results; sometimes informally referred

Do We Deserve Full Credit?

Page 18: Refactotum #6 2G Experiencerefactor |rē㷦faktər| verb to improve a program’s readability or simplify its structure without changing its results; sometimes informally referred

Edge Cases Matter

Page 19: Refactotum #6 2G Experiencerefactor |rē㷦faktər| verb to improve a program’s readability or simplify its structure without changing its results; sometimes informally referred

Is 100% Enough?

Page 20: Refactotum #6 2G Experiencerefactor |rē㷦faktər| verb to improve a program’s readability or simplify its structure without changing its results; sometimes informally referred

Still Not Exactly Elegant

Page 21: Refactotum #6 2G Experiencerefactor |rē㷦faktər| verb to improve a program’s readability or simplify its structure without changing its results; sometimes informally referred

If Only It Were Groovy

Page 22: Refactotum #6 2G Experiencerefactor |rē㷦faktər| verb to improve a program’s readability or simplify its structure without changing its results; sometimes informally referred

Trolling for “Thorny Logic”

Page 23: Refactotum #6 2G Experiencerefactor |rē㷦faktər| verb to improve a program’s readability or simplify its structure without changing its results; sometimes informally referred

Red, Green, Refactor

Page 24: Refactotum #6 2G Experiencerefactor |rē㷦faktər| verb to improve a program’s readability or simplify its structure without changing its results; sometimes informally referred

First, the Tests

Page 25: Refactotum #6 2G Experiencerefactor |rē㷦faktər| verb to improve a program’s readability or simplify its structure without changing its results; sometimes informally referred

Greenlit for Refactoring

Page 26: Refactotum #6 2G Experiencerefactor |rē㷦faktər| verb to improve a program’s readability or simplify its structure without changing its results; sometimes informally referred

If it’s broke, then fix it. If it’s whack, remix it. -- Everlast, Money

Page 27: Refactotum #6 2G Experiencerefactor |rē㷦faktər| verb to improve a program’s readability or simplify its structure without changing its results; sometimes informally referred

Problem: Too Much Repetition

Page 28: Refactotum #6 2G Experiencerefactor |rē㷦faktər| verb to improve a program’s readability or simplify its structure without changing its results; sometimes informally referred

Solution: DRY It Up

Page 29: Refactotum #6 2G Experiencerefactor |rē㷦faktər| verb to improve a program’s readability or simplify its structure without changing its results; sometimes informally referred

Problem: Too Many Conditions

Page 30: Refactotum #6 2G Experiencerefactor |rē㷦faktər| verb to improve a program’s readability or simplify its structure without changing its results; sometimes informally referred

Solution: Defaults + Extraction

Page 31: Refactotum #6 2G Experiencerefactor |rē㷦faktər| verb to improve a program’s readability or simplify its structure without changing its results; sometimes informally referred

Solution: Defaults + Extraction(Continued)

Page 32: Refactotum #6 2G Experiencerefactor |rē㷦faktər| verb to improve a program’s readability or simplify its structure without changing its results; sometimes informally referred

# Verify all tests passgrails> ant test-with-coverage...BUILD SUCCESSFUL

# Verify test coverage still at 100%grails> open cruise/coverage/report/index.html

# Create the patchgrails> svn diff > refactotum_2gx.diff

Test, Patch, Repeat

Page 33: Refactotum #6 2G Experiencerefactor |rē㷦faktər| verb to improve a program’s readability or simplify its structure without changing its results; sometimes informally referred

Login to JIRAhttp://jira.codehaus.org

Page 34: Refactotum #6 2G Experiencerefactor |rē㷦faktər| verb to improve a program’s readability or simplify its structure without changing its results; sometimes informally referred

Submit Patch

Page 35: Refactotum #6 2G Experiencerefactor |rē㷦faktər| verb to improve a program’s readability or simplify its structure without changing its results; sometimes informally referred

Wrapping Up

Removed build noise

Added missing tests to build

Provided better unit tests for WebUtils.java

Increased test coverage for GroovyIfTag.java

Refactored GroovyIfTag.java

Increased DRYness

Reduced complexity

Contributions Come in Many Flavors

Page 36: Refactotum #6 2G Experiencerefactor |rē㷦faktər| verb to improve a program’s readability or simplify its structure without changing its results; sometimes informally referred

Resources

This Week in Refactoring

blog.thinkrelevance.com/twir

Jay Fields on Test Quality and Coverage

blog.jayfields.com/2008/02/tests-reflect-code-quality.html

Page 37: Refactotum #6 2G Experiencerefactor |rē㷦faktər| verb to improve a program’s readability or simplify its structure without changing its results; sometimes informally referred

Resources

Are You Covered?

en.wikipedia.org/wiki/code_coverage

cobertura.sourceforge.net

build.canoo.com/grails/artifacts/coverage/index.html

(Continued)

Page 38: Refactotum #6 2G Experiencerefactor |rē㷦faktər| verb to improve a program’s readability or simplify its structure without changing its results; sometimes informally referred

Refactotum JIRA Tickets

jira.codehaus.org/browse/GRAILS-2412

jira.codehaus.org/browse/GRAILS-2469

jira.codehaus.org/browse/GRAILS-2470

jira.codehaus.org/browse/GRAILS-2471

Resources(Continued)

Page 39: Refactotum #6 2G Experiencerefactor |rē㷦faktər| verb to improve a program’s readability or simplify its structure without changing its results; sometimes informally referred

This presentation is published under the Creative Commons Attribution Noncommercial Share Alike License Version 2.5.

(Please see http://creativecommons.org/licenses/by-nc-sa/2.5 for complete details.)

Let’s Contribute!Workshop