refactoring the tennis kata v2 (2016)

24
Coding Dojo: Refactoring the Tennis Kata October 2016 Peter Kofler, ‘Code Cop’ @codecopkofler www.code-cop.org Copyright Peter Kofler, licensed under CC-BY.

Upload: peter-kofler

Post on 18-Feb-2017

158 views

Category:

Technology


4 download

TRANSCRIPT

Page 1: Refactoring the Tennis Kata v2 (2016)

Coding Dojo:Refactoring the

Tennis KataOctober 2016

Peter Kofler, ‘Code Cop’@codecopkofler

www.code-cop.org

Copyright Peter Kofler, licensed under CC-BY.

Page 2: Refactoring the Tennis Kata v2 (2016)

Peter Kofler

• Ph.D. (Appl. Math.)

• Professional SoftwareDeveloper for 15+ years

• “fanatic about code quality”

• I help development teams

PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY

Page 3: Refactoring the Tennis Kata v2 (2016)

I help development teams with

PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY

● Professionalism

● Quality and Productivity

● Continuous Improvement

Page 4: Refactoring the Tennis Kata v2 (2016)

Mentoring

PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY

● Pair Programming

● ProgrammingWorkshops

● DeliberatePractice, e.g. Coding Dojos

Page 5: Refactoring the Tennis Kata v2 (2016)

Developing Quality Software Developers

Page 6: Refactoring the Tennis Kata v2 (2016)

Coding Dojo?Expectations?

Page 7: Refactoring the Tennis Kata v2 (2016)

Coding Dojo Mindset

● Safe place outsidework

● We are here to learn● Need to slow down● Focus on doing it right● Collaborative Game

PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY

Page 8: Refactoring the Tennis Kata v2 (2016)

Dojo Structure

● Introduction 15'● Coding 60'● Retrospective 15'● Break 15'● Coding 60'● Retrospective 15'● etc.

PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY

Page 9: Refactoring the Tennis Kata v2 (2016)

Refactoring

Refactoring is a technique for restructuring

an existing body of code, altering its internal structure

without changing its external behaviour.

(Martin Fowler)

PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY

Page 10: Refactoring the Tennis Kata v2 (2016)

Identify Code Smells

● Code Smells are indications of a deeper problem in the system.

● e.g.● bad names,● duplication,● call chains,● missing object

orientation,● etc.

PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY

Page 11: Refactoring the Tennis Kata v2 (2016)

Refactor Mercilessly

PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY

● mer·ci·less is defined ashaving or showing no mercy, cold-blooded, hard-boiled, heartless, insensitive, hard, pitiless, remorseless, ruthless, slash-and-burn, soulless, take-no-prisoners, unfeeling, unsympathetic

● e.g. „extract till you drop“https://sites.google.com/site/unclebobconsultingllc/one-thing-extract-till-you-drop

Page 12: Refactoring the Tennis Kata v2 (2016)

TDD Skills

● Driving Development with Tests● Designing Test Cases● Designing Clean Code● Refactoring Safely

PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY

Page 13: Refactoring the Tennis Kata v2 (2016)

Assignment: Tennis

PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY

Page 14: Refactoring the Tennis Kata v2 (2016)

Scoring a Tennis Game

● The Scoring Algorithm is done.● Covered by a complete suite of test.● You need to clean-up the code.● Refactor Mercilessly!● Work in small steps. („Baby Steps“)● Rely on the tests, run them often.● Experiment with approaches.

PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY

Page 15: Refactoring the Tennis Kata v2 (2016)

Constraints

● Challenges during a dojo or coderetreat

● Moving to the extreme is a way of learning

● Examples● Missing Tool (No Mouse, …)● Missing Feature (No IFs, …)

PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY

Page 16: Refactoring the Tennis Kata v2 (2016)

Only Use Refactoring Tools

PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY

Page 17: Refactoring the Tennis Kata v2 (2016)

Constraint: Refactoring Tools

● Using automatic refactoring is less risky.● Only use refactoring tools of your IDE.

● e.g. Extract Variable, Inline Method, ...

● If you (have to) change code manually● undo that change and● think of a way to do the same change● with a series of automatic refactorings.

PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY

Page 18: Refactoring the Tennis Kata v2 (2016)

Constraint: No Mouse

PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY

Page 19: Refactoring the Tennis Kata v2 (2016)

Prepare

● Find a pair.● Get the code. (“Download Zip”)● Run tests, see many green tests.● Start with TennisGame #2.● Focus entirely on clean-up.● Identify code smells.● Try to use only automatic Refactorings.

PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY

Page 20: Refactoring the Tennis Kata v2 (2016)

Don't Focus on Getting it Done.F0cus on Doing

It Perfectly.

Page 21: Refactoring the Tennis Kata v2 (2016)

→Practice

Page 22: Refactoring the Tennis Kata v2 (2016)

Closing Circle

● What did you learn today?

● What surprised you today?

● What will you do differently in the future?

PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY

Page 23: Refactoring the Tennis Kata v2 (2016)

Peter Kofler@codecopkofler

www.code-cop.org

Kata by

Emily Bache@emilybache

http://coding-is-like-cooking.info/2011/08/refactoring-kata-fun/

PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY

Page 24: Refactoring the Tennis Kata v2 (2016)

CC Images● Bruce http://www.flickr.com/photos/sherpas428/4350620602/● pairing http://www.flickr.com/photos/dav/94735395/● Dojo http://www.flickr.com/photos/49715404@N00/3267627038/● agenda http://www.flickr.com/photos/24293932@N00/2752221871/● smells http://www.flickr.com/photos/hhbw/4215183405/● mercy http://www.flickr.com/photos/williac/99551756/● Tennis http://www.flickr.com/photos/gagillphoto/3706167856/● tools https://www.flickr.com/photos/tom-margie/5019211728/● trap https://www.flickr.com/photos/stevendepolo/13714018553/● wants you http://www.flickr.com/photos/shutter/105497713/

PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY