refactoring for observation · 2020-01-24 · refactoring “ refactoring (2nd edition) ” -...

52
Refactoring For Observation Novel Practices for Learning Code Freeze 2020 David Laribee | [email protected]

Upload: others

Post on 27-May-2020

46 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Refactoring For Observation · 2020-01-24 · Refactoring “ Refactoring (2nd Edition) ” - Fowler “ Refactoring to Patterns ” - Kerievsky Smells to Refactoring Cheat Sheet

Refactoring For ObservationNovel Practices for Learning

Code Freeze 2020David Laribee | [email protected]

Page 2: Refactoring For Observation · 2020-01-24 · Refactoring “ Refactoring (2nd Edition) ” - Fowler “ Refactoring to Patterns ” - Kerievsky Smells to Refactoring Cheat Sheet

@laribee

ObviousCause and effect are repeatable and predictable.

Best Practice(Sense-Categorize-Respond)

Standard Operating Procedures; Automation

ComplicatedCause and effect are separated over time and space.

Good Practice(Sense-Analyze-Respond)

Predictive Planning; Rules; Expert Analysis

ComplexCause and effect seen in retrospect and do not repeat.

Emergent Practice(Probe-Sense-Respond)

Pattern Matching; Heuristics; Experimentation

ChaoticCause and effect are not usually perceivable.

Novel Practice(Act-Sense-Respond)

Intervention; Crises Management; Rescue

Disorder

Page 3: Refactoring For Observation · 2020-01-24 · Refactoring “ Refactoring (2nd Edition) ” - Fowler “ Refactoring to Patterns ” - Kerievsky Smells to Refactoring Cheat Sheet

@laribee

ObviousCause and effect are repeatable and predictable.

Best Practice(Sense-Categorize-Respond)

Standard Operating Procedures; Automation

ComplicatedCause and effect are separated over time and space.

Good Practice(Sense-Analyze-Respond)

Predictive Planning; Rules; Expert Analysis

ComplexCause and effect seen in retrospect and do not repeat.

Emergent Practice(Probe-Sense-Respond)

Pattern Matching; Heuristics; Experimentation

ChaoticCause and effect are not usually perceivable.

Novel Practice(Act-Sense-Respond)

Intervention; Crises Management; Rescue

Disorder

Page 4: Refactoring For Observation · 2020-01-24 · Refactoring “ Refactoring (2nd Edition) ” - Fowler “ Refactoring to Patterns ” - Kerievsky Smells to Refactoring Cheat Sheet

@laribee

ObviousCause and effect are repeatable and predictable.

Best Practice(Sense-Categorize-Respond)

Standard Operating Procedures; Automation

ComplicatedCause and effect are separated over time and space.

Good Practice(Sense-Analyze-Respond)

Predictive Planning; Rules; Expert Analysis

ComplexCause and effect seen in retrospect and do not repeat.

Emergent Practice(Probe-Sense-Respond)

Pattern Matching; Heuristics; Experimentation

ChaoticCause and effect are not usually perceivable.

Novel Practice(Act-Sense-Respond)

Intervention; Crises Management; Rescue

Disorder

Page 5: Refactoring For Observation · 2020-01-24 · Refactoring “ Refactoring (2nd Edition) ” - Fowler “ Refactoring to Patterns ” - Kerievsky Smells to Refactoring Cheat Sheet

@laribee

ObviousCause and effect are repeatable and predictable.

Best Practice(Sense-Categorize-Respond)

Standard Operating Procedures; Automation

ComplicatedCause and effect are separated over time and space.

Good Practice(Sense-Analyze-Respond)

Predictive Planning; Rules; Expert Analysis

ComplexCause and effect seen in retrospect and do not repeat.

Emergent Practice(Probe-Sense-Respond)

Pattern Matching; Heuristics; Experimentation

ChaoticCause and effect are not usually perceivable.

Novel Practice(Act-Sense-Respond)

Intervention; Crises Management; Rescue

Disorder

Page 6: Refactoring For Observation · 2020-01-24 · Refactoring “ Refactoring (2nd Edition) ” - Fowler “ Refactoring to Patterns ” - Kerievsky Smells to Refactoring Cheat Sheet

Architectural Mapping

@laribee

Page 7: Refactoring For Observation · 2020-01-24 · Refactoring “ Refactoring (2nd Edition) ” - Fowler “ Refactoring to Patterns ” - Kerievsky Smells to Refactoring Cheat Sheet

@laribee

Page 8: Refactoring For Observation · 2020-01-24 · Refactoring “ Refactoring (2nd Edition) ” - Fowler “ Refactoring to Patterns ” - Kerievsky Smells to Refactoring Cheat Sheet

Architectural MapsDiffer from traditional diagrams; they’re maps.Are based on the “C4 Model” by Simon Brown.Combine static structure with a planned and annotated route path.

@laribee

Page 9: Refactoring For Observation · 2020-01-24 · Refactoring “ Refactoring (2nd Edition) ” - Fowler “ Refactoring to Patterns ” - Kerievsky Smells to Refactoring Cheat Sheet

@laribee

Source: Simon Brown, “The C4 Model of Software Architecture”

Page 10: Refactoring For Observation · 2020-01-24 · Refactoring “ Refactoring (2nd Edition) ” - Fowler “ Refactoring to Patterns ” - Kerievsky Smells to Refactoring Cheat Sheet
Page 11: Refactoring For Observation · 2020-01-24 · Refactoring “ Refactoring (2nd Edition) ” - Fowler “ Refactoring to Patterns ” - Kerievsky Smells to Refactoring Cheat Sheet
Page 12: Refactoring For Observation · 2020-01-24 · Refactoring “ Refactoring (2nd Edition) ” - Fowler “ Refactoring to Patterns ” - Kerievsky Smells to Refactoring Cheat Sheet
Page 13: Refactoring For Observation · 2020-01-24 · Refactoring “ Refactoring (2nd Edition) ” - Fowler “ Refactoring to Patterns ” - Kerievsky Smells to Refactoring Cheat Sheet

C4 Model + Journeys

C1 - System Landscape and/or ContextC2 - Container Diagrams (Stacks & Deploy)C3 - Component Diagram (Logical Arch.)Journeys - Data Flows, Extraction Plan

@laribee

Page 14: Refactoring For Observation · 2020-01-24 · Refactoring “ Refactoring (2nd Edition) ” - Fowler “ Refactoring to Patterns ” - Kerievsky Smells to Refactoring Cheat Sheet

@laribee

Page 15: Refactoring For Observation · 2020-01-24 · Refactoring “ Refactoring (2nd Edition) ” - Fowler “ Refactoring to Patterns ” - Kerievsky Smells to Refactoring Cheat Sheet

@laribee

Page 16: Refactoring For Observation · 2020-01-24 · Refactoring “ Refactoring (2nd Edition) ” - Fowler “ Refactoring to Patterns ” - Kerievsky Smells to Refactoring Cheat Sheet

@laribee

Page 17: Refactoring For Observation · 2020-01-24 · Refactoring “ Refactoring (2nd Edition) ” - Fowler “ Refactoring to Patterns ” - Kerievsky Smells to Refactoring Cheat Sheet

@laribee

Page 18: Refactoring For Observation · 2020-01-24 · Refactoring “ Refactoring (2nd Edition) ” - Fowler “ Refactoring to Patterns ” - Kerievsky Smells to Refactoring Cheat Sheet

@laribee

Page 19: Refactoring For Observation · 2020-01-24 · Refactoring “ Refactoring (2nd Edition) ” - Fowler “ Refactoring to Patterns ” - Kerievsky Smells to Refactoring Cheat Sheet

@laribee

Page 20: Refactoring For Observation · 2020-01-24 · Refactoring “ Refactoring (2nd Edition) ” - Fowler “ Refactoring to Patterns ” - Kerievsky Smells to Refactoring Cheat Sheet

@laribee

Page 21: Refactoring For Observation · 2020-01-24 · Refactoring “ Refactoring (2nd Edition) ” - Fowler “ Refactoring to Patterns ” - Kerievsky Smells to Refactoring Cheat Sheet

@laribee

Page 22: Refactoring For Observation · 2020-01-24 · Refactoring “ Refactoring (2nd Edition) ” - Fowler “ Refactoring to Patterns ” - Kerievsky Smells to Refactoring Cheat Sheet

Sum Up

Make architecture a social activity!People are a part of your system, too. If they don’t understand your architecture, they may be operating from a position of chaos or complexity.

@laribee

Page 23: Refactoring For Observation · 2020-01-24 · Refactoring “ Refactoring (2nd Edition) ” - Fowler “ Refactoring to Patterns ” - Kerievsky Smells to Refactoring Cheat Sheet

Sum Up

Plot journeys in diagrams to previsualize risky changes or large scale refactorings.Only diagram what you need to. Remember: diagrams, just like code, need maintenance.

@laribee

Page 24: Refactoring For Observation · 2020-01-24 · Refactoring “ Refactoring (2nd Edition) ” - Fowler “ Refactoring to Patterns ” - Kerievsky Smells to Refactoring Cheat Sheet

Refactoring With Telemetry

@laribee

Page 25: Refactoring For Observation · 2020-01-24 · Refactoring “ Refactoring (2nd Edition) ” - Fowler “ Refactoring to Patterns ” - Kerievsky Smells to Refactoring Cheat Sheet

Refactoring

Changing the structure of an application without changing its behavior.Helps introduce new domain concepts and in moving from specific to general (abstraction).A healthy part of a complete XP breakfast.

@laribee

Page 26: Refactoring For Observation · 2020-01-24 · Refactoring “ Refactoring (2nd Edition) ” - Fowler “ Refactoring to Patterns ” - Kerievsky Smells to Refactoring Cheat Sheet

TDD + Refactoring

@laribee

Refactor

Red

Green

Write just enough code to make the new test pass.

Ensure all tests pass.

Write a new test to extend the behavior of

the system.

Make structural changes to improve clarity and lessen cognitive load.

Page 27: Refactoring For Observation · 2020-01-24 · Refactoring “ Refactoring (2nd Edition) ” - Fowler “ Refactoring to Patterns ” - Kerievsky Smells to Refactoring Cheat Sheet

Refactoring Problems

If you didn’t start with TDD, it can be difficult.Optimally backed by a “safety net” test suite.High-skill,-discipline, and -commitment.Refactor to what?!

@laribee

Page 28: Refactoring For Observation · 2020-01-24 · Refactoring “ Refactoring (2nd Edition) ” - Fowler “ Refactoring to Patterns ” - Kerievsky Smells to Refactoring Cheat Sheet

Refactor to what?!

Principles and heuristics such as SOLID.Domain alignment à la DDD.Lighter cognitive load, better Developer Experience.

@laribee

Page 29: Refactoring For Observation · 2020-01-24 · Refactoring “ Refactoring (2nd Edition) ” - Fowler “ Refactoring to Patterns ” - Kerievsky Smells to Refactoring Cheat Sheet

TDD + Refactoring

@laribee

Refactor

Red

Green

Write just enough code to make the new test pass.

Ensure all tests pass.

Write a new test to extend the behavior of

the system.

Make structural changes to improve clarity and lessen cognitive load.

Page 30: Refactoring For Observation · 2020-01-24 · Refactoring “ Refactoring (2nd Edition) ” - Fowler “ Refactoring to Patterns ” - Kerievsky Smells to Refactoring Cheat Sheet

A Different Loop

@laribee

Target

Find your refactoring target(s).

Page 31: Refactoring For Observation · 2020-01-24 · Refactoring “ Refactoring (2nd Edition) ” - Fowler “ Refactoring to Patterns ” - Kerievsky Smells to Refactoring Cheat Sheet

Targeting Change

Intuition- or consensus-based.Archeological - “we have N ways”Code smells - “Primitive Obsession”Visualization or data-driven, e.g. cyclomatic complexity plus method size.

@laribee

Page 32: Refactoring For Observation · 2020-01-24 · Refactoring “ Refactoring (2nd Edition) ” - Fowler “ Refactoring to Patterns ” - Kerievsky Smells to Refactoring Cheat Sheet

A Different Loop

@laribee

Target

Execute refactoring experiments and runs until

satisfied.

Find your refactoring target(s).

Refactor

LearnUse telemetry, discussion,

and teaching to discuss proposed changes.

Page 33: Refactoring For Observation · 2020-01-24 · Refactoring “ Refactoring (2nd Edition) ” - Fowler “ Refactoring to Patterns ” - Kerievsky Smells to Refactoring Cheat Sheet

Refactor, Learn, Repeat

Aesthetic convergence - “how we do it.”Temporary technical coaching; after several weeks the team no longer needs them.SQALE and other code quality metrics add some nice data to the conversations.

@laribee

Page 34: Refactoring For Observation · 2020-01-24 · Refactoring “ Refactoring (2nd Edition) ” - Fowler “ Refactoring to Patterns ” - Kerievsky Smells to Refactoring Cheat Sheet

A Different Loop

@laribee

Refactor

Target

LearnExecute refactoring

experiments and runs until satisfied.

Find your refactoring target(s).

Use telemetry, discussion, and teaching to discuss

proposed changes.

CommitPushing units. Making bank.

Page 36: Refactoring For Observation · 2020-01-24 · Refactoring “ Refactoring (2nd Edition) ” - Fowler “ Refactoring to Patterns ” - Kerievsky Smells to Refactoring Cheat Sheet
Page 37: Refactoring For Observation · 2020-01-24 · Refactoring “ Refactoring (2nd Edition) ” - Fowler “ Refactoring to Patterns ” - Kerievsky Smells to Refactoring Cheat Sheet
Page 38: Refactoring For Observation · 2020-01-24 · Refactoring “ Refactoring (2nd Edition) ” - Fowler “ Refactoring to Patterns ” - Kerievsky Smells to Refactoring Cheat Sheet
Page 39: Refactoring For Observation · 2020-01-24 · Refactoring “ Refactoring (2nd Edition) ” - Fowler “ Refactoring to Patterns ” - Kerievsky Smells to Refactoring Cheat Sheet
Page 40: Refactoring For Observation · 2020-01-24 · Refactoring “ Refactoring (2nd Edition) ” - Fowler “ Refactoring to Patterns ” - Kerievsky Smells to Refactoring Cheat Sheet
Page 41: Refactoring For Observation · 2020-01-24 · Refactoring “ Refactoring (2nd Edition) ” - Fowler “ Refactoring to Patterns ” - Kerievsky Smells to Refactoring Cheat Sheet
Page 42: Refactoring For Observation · 2020-01-24 · Refactoring “ Refactoring (2nd Edition) ” - Fowler “ Refactoring to Patterns ” - Kerievsky Smells to Refactoring Cheat Sheet
Page 43: Refactoring For Observation · 2020-01-24 · Refactoring “ Refactoring (2nd Edition) ” - Fowler “ Refactoring to Patterns ” - Kerievsky Smells to Refactoring Cheat Sheet
Page 44: Refactoring For Observation · 2020-01-24 · Refactoring “ Refactoring (2nd Edition) ” - Fowler “ Refactoring to Patterns ” - Kerievsky Smells to Refactoring Cheat Sheet
Page 45: Refactoring For Observation · 2020-01-24 · Refactoring “ Refactoring (2nd Edition) ” - Fowler “ Refactoring to Patterns ” - Kerievsky Smells to Refactoring Cheat Sheet
Page 46: Refactoring For Observation · 2020-01-24 · Refactoring “ Refactoring (2nd Edition) ” - Fowler “ Refactoring to Patterns ” - Kerievsky Smells to Refactoring Cheat Sheet

Sum Up

Use metrics like cyclomatic complexity, method size (LoC), and SQALE to spark insight and observe relationships.Return to safety (git checkout .) when things get wonky; they will.

@laribee

Page 47: Refactoring For Observation · 2020-01-24 · Refactoring “ Refactoring (2nd Edition) ” - Fowler “ Refactoring to Patterns ” - Kerievsky Smells to Refactoring Cheat Sheet

Sum Up

Use an automated refactoring tool!Do this in a group. I like mob programming for this kind of session.You will speed up and find refactoring you can apply to other areas of your codebase.

@laribee

Page 48: Refactoring For Observation · 2020-01-24 · Refactoring “ Refactoring (2nd Edition) ” - Fowler “ Refactoring to Patterns ” - Kerievsky Smells to Refactoring Cheat Sheet

@laribee

Page 49: Refactoring For Observation · 2020-01-24 · Refactoring “ Refactoring (2nd Edition) ” - Fowler “ Refactoring to Patterns ” - Kerievsky Smells to Refactoring Cheat Sheet

@laribee

Page 50: Refactoring For Observation · 2020-01-24 · Refactoring “ Refactoring (2nd Edition) ” - Fowler “ Refactoring to Patterns ” - Kerievsky Smells to Refactoring Cheat Sheet

@laribee

Page 51: Refactoring For Observation · 2020-01-24 · Refactoring “ Refactoring (2nd Edition) ” - Fowler “ Refactoring to Patterns ” - Kerievsky Smells to Refactoring Cheat Sheet

@laribee

Page 52: Refactoring For Observation · 2020-01-24 · Refactoring “ Refactoring (2nd Edition) ” - Fowler “ Refactoring to Patterns ” - Kerievsky Smells to Refactoring Cheat Sheet

Thank You!

Code Freeze 2020David Laribee | [email protected]