10. Simple Design
1. All tests must pass
2. No code is duplicated
3. Code is self-explanatory
4. No superfluous parts exist
11.
12. Simple Design
1. All tests must pass
2. No code is duplicated
3. Code is self-explanatory
4. No superfluous parts exist
13. Simple Design
1. Passes its tests
2. No code is duplicated
3. Code is self-explanatory
4. No superfluous parts exist
14. Simple Design
1. Passes its tests
2. Minimizes duplication
3. Code is self-explanatory
4. No superfluous parts exist
15. Simple Design
1. Passes its tests
2. Minimizes duplication
3. Maximizes clarity
4. No superfluous parts exist
16. Simple Design
1. Passes its tests
2. Minimizes duplication
3. Maximizes clarity
4. Has fewer elements
17. Simple Design
1. Passes its tests (given TDD)
2. Minimizes duplication
3. Maximizes clarity
4. Has fewer elements
18. Simple Design
1. Passes its tests (given TDD)
2. Minimizes duplication
3. Maximizes clarity (fix names)
4. Has fewer elements
19. Simple Design
1. Passes its tests (given TDD)
2. Minimizes duplication
3. Maximizes clarity (fix names)
4. Has fewer elements
20. That leaves me with two key elements
of simple design: remove duplication and
fix bad names.
When I remove duplication, I tend to see
an appropriate structure emerge, and when
I fix bad names, I tend to see responsibilities
slide into appropriate parts of the design.
J. B. Rainsberger
44. CComBstr sVal $.getJSON() int result
Rx rx applyMeasureConstraintToEnableSortingByMeasure() float hp
applyPhq9DateRangeConstraint() public void run() Date genymdhms
m_name Label label IShapeFactory
Customer int i RollOverPerformanceIndicatorsToNextMonthTask
CustomerManager LPSTR lpCmdLine int daysSinceModification
boolean fNewPage UpdatePerfIndValueDecCountCmd DepressionSelfManagementCalculator
Tutorial02
PerfIndValueDecCountForMatchingIvpCmd PulseRenderer IndexCardPageLayout sut
45. CComBstr sVal $.getJSON() int result
Rx rx applyMeasureConstraintToEnableSortingByMeasure() float hp
applyPhq9DateRangeConstraint() public void run() Date genymdhms
m_name Label label IShapeFactory
Customer int i RollOverPerformanceIndicatorsToNextMonthTask
CustomerManager LPSTR lpCmdLine int daysSinceModification
boolean fNewPage UpdatePerfIndValueDecCountCmd DepressionSelfManagementCalculator
Tutorial02
PerfIndValueDecCountForMatchingIvpCmd PulseRenderer IndexCardPageLayout sut
46. Find a partner and each of you:
1. select a name you thought was good
2. explain why to your partner
3. select a name you thought was bad
4. explain why to your partner
CComBstr sVal $.getJSON() int result
Rx rx applyMeasureConstraintToEnableSortingByMeasure() float hp
applyPhq9DateRangeConstraint() public void run() Date genymdhms
m_name Label label IShapeFactory
Customer int i RollOverPerformanceIndicatorsToNextMonthTask
CustomerManager LPSTR lpCmdLine int daysSinceModification
boolean fNewPage UpdatePerfIndValueDecCountCmd DepressionSelfManagementCalculator
PerfIndValueDecCountForMatchingIvpCmd PulseRenderer IndexCardPageLayout sut
48. Choosing Good Names
Use the telephone test for readability.
If someone could understand your
code when read aloud over the
telephone, it's clear enough.
If not, then it needs rewriting.
50. Choosing Good Names
Splitters can be lumped more easily
than lumpers can be split.
It is easier to combine two concepts
that it is to separate them.
70. Ubiquitous Language
applyPhq9DateRangeConstraint()
The PHQ-9 is the nine item depression scale of
the Patient Health Questionnaire.
The PHQ-9 is a powerful tool for assisting primary
care clinicians in diagnosing depression as well as
selecting and monitoring treatment.
73. Choosing Good Names
•Locate one
Naming'Guidelines
System'of'Names
S1# # Name#pass#the#“telephone”#test.
S2# # There#is#a#clean#name#for#each#concept.#Remember:#later#on#it’s#easier#to#lump#
guideline that if
things#together#than#to#split#them#apart.
S3# # Name#is#from#the#problem#or#solu?on#domain#and#support#ubiquitous#language#for#
the#team
General
applied would have
G1## Name#is#pronounceable.
G2## Name#avoids#encodings#and#member#prefixes.
G3## Name#suggest#why#it#exists.
G4## Name#suggest#how#it#should#be#used.
the biggest impact
G5## Name#suggest#what#it#does.
G6## Name#is#easily#searchable#in#the#code#base.
Classes
C1# If#this#is#an#important#base#class#its#class#name#should#be#a#simple#single#word.
C2#
C3#
If#this#is#a#subclass#its#class#name#suggests#how#it#differs#from#its#superclass.
The#class#name#is#a#noun#or#a#noun#phrase.
on your code
•Find a partner
Methods
M1# The#method#name#suggests#why#it#would#be#called.
M2# The#method#is#name#a#verb#or#a#verb#phrase.
Variables/Fields/Arguments
•Discuss
V1# Its#name#indicate#the#role#it's#playing.
V2# The#length#of#the#name#reflect#its#scope.
Alistair McKinnell @amckinnell Declan Whelan @dwhelan
Naming Guidelines v1.0 August 2012 ! 1/1
74. Choosing Good Names
public List<int[]> getThem() {
List<int[]> list1 = new ArrayList<int[]>();
for (int[] x : theList)
if (x[0] == 4)
list1.add(x);
return list1;
}
Source: Clean Code: A Handbook of Agile Software Craftsmanship, Robert C. Martin, pages 18-19
75. Choosing Good Names
public List<int[]> getThem() {
List<int[]> list1 = new ArrayList<int[]>();
for (int[] x : theList)
if (x[0] == 4)
list1.add(x);
return list1;
}
public List<int[]> getFlaggedCells() {
List<int[]> flaggedCells = new ArrayList<int[]>();
for (int[] cell : gameBoard)
if (cell[STATUS_VALUE] == FLAGGED)
flaggedCells.add(cell);
return flaggedCells;
}
Source: Clean Code: A Handbook of Agile Software Craftsmanship, Robert C. Martin, pages 18-19
76. Choosing Good Names
public List<int[]> getThem() {
List<int[]> list1 = new ArrayList<int[]>();
for (int[] x : theList)
if (x[0] == 4)
list1.add(x);
return list1;
}
public List<Cell> getFlaggedCells() {
List<Cell> flaggedCells = new ArrayList<Cell>();
for (Cell cell : gameBoard)
if (cell.isFlagged())
flaggedCells.add(cell);
return flaggedCells;
}
Source: Clean Code: A Handbook of Agile Software Craftsmanship, Robert C. Martin, pages 18-19
77. Choosing Good Names
public List<int[]> getThem() {
List<int[]> list1 = new ArrayList<int[]>();
for (int[] x : theList)
if (x[0] == 4)
list1.add(x);
return list1;
}
public List<Cell> getFlaggedCells() {
List<Cell> result = new ArrayList<Cell>();
for (Cell cell : gameBoard)
if (cell.isFlagged())
result.add(cell);
return result;
}
Source: Clean Code: A Handbook of Agile Software Craftsmanship, Robert C. Martin, pages 18-19
78. Choosing Good Names
int s = 0;
for (int j=0; j<34; j++) {
s += (t[j]*4)/5;
}
const int EFFECTIVE_DAYS_PER_WEEK = 4;
int realDaysPerIdealDay = 4;
const int WORKING_DAYS_PER_WEEK = 5;
const int WORK_DAYS_PER_WEEK = 5;
int sum = 0;
int effectiveTotalEstimate = 0;
for (int j=0; j < NUMBER_OF_TASKS; j++) {
for (int j=0; j < NUMBER_OF_TASKS; j++) {realDaysPerIdealDay;
int realTaskDays = taskEstimate[j] *
int effectiveTaskEstimate =
int realTaskWeeks = (realdays / WORK_DAYS_PER_WEEK);
taskEstimate[j] * EFFECTIVE_DAYS_PER_WEEK / WORKING_DAYS_PER_WEEK;
sum += realTaskWeeks;
effectiveTotalEstimate += effectiveTaskEstimate;
}
}
Source: Clean Code: A Handbook of Agile Software Craftsmanship, Robert C. Martin, page 23
84. How do you handle
duplicate code
in your codebase?
85.
86. Avoiding Duplicate Code
DRY: Don’t Repeat Yourself
Every piece of knowledge must have
a single, unambiguous, authoritative
representation within a system.
87. Avoiding Duplicate Code
Once and Only Once
Data, structure, or logic should exist
in only one place in the system.
88. Avoiding Duplicate Code
Test-Driven Development
1. Write new code only if an
automated test has failed.
2. Eliminate duplication.
89. Avoiding Duplicate Code
Single Choice Principle
Whenever a software system must
support a set of alternatives, one
and only one module in the system
should know their exhaustive list.
108. Select Options
SelectOptions SelectOptionsSource
create() getFirst()
getLast()
isSelected()
Commonality Variability Resolution
Data Structure Value of State Simple Java Type
131. “The prime directive that was
unanimously agree upon by all
present was that in the next
tens years Agile leaders must
Demand Technical Excellence.”
Jeff Sutherland
132. “Failure to do that means
you are not an Agile leader.”
Jeff Sutherland
134. Reading
The Elements of Programming Style
Kernighan and Plauger
Prefactoring
Extreme Abstraction Extreme Separation Extreme Readability
Ken Pugh
Pragmatic
Programmers Agile in a Flash
Speed-Learning Agile
Software Development
Agile in a Flash
Agile Cards for
Agile Teams Speed-Learning Agile Development
Jeff Langr and
Tim Ottinger
edited by Susannah Pfalzer
Jeff Langr and Tim Ottinger
Prepared exclusively for Alistair McKinnell
135. Reading
Clean Code
A Handbook of Agile Software Craftsmanship
Robert C. Martin
Domain Driven Design
Tackling Complexity in the Heart of Software
Eric Evans
Implementation Patterns
Kent Beck
136. Reading
The Pragmatic Programmer: From Journeyman to Master
Andrew Hunt and Dave Thomas
Extreme Programming Explained: Embrace Change
Kent Beck and Cynthia Andres
Test Driven Development: By Example
Kent Beck
Object-Oriented Software Construction
Bertrand Meyer
137. Reading
Design Patterns: Elements of Reusable
Object-Oriented Software Erich Gamma,
Richard Helm, Ralph Johnson, and John Vlissides
Multi-Paradigm Design for C++
James O. Coplien
Lean Architecture: for Agile Software Development
James O. Coplien and Gertrud Bjørnvig