P2P Naming - WordPress.com

12 downloads 138 Views 3MB Size Report
Code is self-explanatory .... Is%there%a%clean%name%for%each%concept? ... Clean Code: A Handbook of Agile Software Craftsmanship, Robert C. Martin, ...
What's in a Name? Increase Productivity Through Effective Naming

Alistair McKinnell @amckinnell

Declan Whelan @dwhelan

I❤ Scrum

“Scrum is not a process or a technique for building products; rather, it is a framework within which you can employ various processes and techniques.” Scrum Guide

0

10

20

30

40

50

60

70

80

“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

“Failure to do that means you are not an Agile leader.”

Jeff Sutherland

www.XProgramming.com

Simple Design 1. All tests must pass 2. No code is duplicated 3. Code is self-explanatory 4. No superfluous parts exist

Simple Design 1. All tests must pass 2. No code is duplicated 3. Code is self-explanatory 4. No superfluous parts exist

Simple Design 3. Code is self-explanatory



Choosing good names

Exercise

Stroop Effect Green Red Blue Purple Blue Purple Blue Purple Red Green Purple Green

Meaning:

Colour:

black yellow

Meaning:

Colour:

blue black

black yellow

yellow red

red yellow

red yellow

blue blue

yellow blue

red red

blue red

yellow yellow

red yellow

red yellow

blue black

yellow black

black blue

red black

The End

Exercise

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

Choosing Good Names

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.

Choosing Good Names Goal Donor vs Gold Owner Date genymdhms

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.

Choosing Good Names Customer Address

Choosing Good Names Customer Address

Billing Address

Mailing Address

Service Address

Choosing Good Names Billing Address

Mailing Address

Service Address

Choosing Good Names Billing Address

Mailing Address

Customer Address

Service Address

Choosing Good Names Pronounceable Names Avoid Encodings

Pronounceable Names UpdatePerfIndValueDecCountCmd

Pronounceable Names UpdatePerfIndValueDecCountCmd DecrementAggregateCommand

Pronounceable Names Date genymdhms

Pronounceable Names Date genymdhms Date generatedTimestamp

Avoid Encoding LPSTR lpCmdLine m_name

Choosing Good Names Intention-Revealing Name Role-Suggesting Name

Intention-Revealing Name applyMeasureConstraintTo EnableSortingByMeasure()

Intention-Revealing Name applyMeasureConstraintTo EnableSortingByMeasure() applyMeasureConstraint()

Role-Suggesting Name int result IndexCardPageLayout sut

Choosing Good Names Ubiquitous Language

Ubiquitous Language CComBstr sVal

Ubiquitous Language CComBstr sVal CComBstr calibrationToolName

Ubiquitous Language Rx rx

Ubiquitous Language Rx rx Rx refillable

Ubiquitous Language applyPhq9DateRangeConstraint()

Pragmatic Programmers

Agile in a Flash Speed-Learning Agile Software Development Agile Cards for Agile Teams

Jeff Langr and Tim Ottinger edited by Susannah Pfalzer

Prepared exclusively for Alistair McKinnell

Copyright ©2011 Pragmatic Programmers

43

Really Meaningful Names

! Are accurate ! Are purposeful ! Are pronounceable ! Begin well ! Are simple ! Depend on context ! Match name length to scope

Prepared exclusively for Alistair McKinnell

Copyright ©2011 Pragmatic Programmers

Choosing Good Names Naming'Checklist System'of'Names Does%the%code%pass%the%“telephone”%test? Is%there%a%clean%name%for%each%concept?%Remember:%later%on%it’s%easier%to%lump% things%together%than%to%split%them%apart. Does%the%code%use%ubiquitous%language?%Have%the%names%been%taken%from%the% problem%or%soluAon%domain?

General Is%the%name%pronounceable? Does%the%name%avoid%encodings%and%member%prefixes? Does%the%name%suggest%why%it%exists? Does%the%name%suggest%how%it%should%be%used? Does%the%name%suggest%what%it%does? Is%the%name%easily%searchable?

Classes If%this%is%an%important%base%class%does%it%have%a%simple%one%word%name? If%this%is%a%subclass%does%its%name%suggest%how%it%is%different%from%its%superclass? Is%the%name%a%noun%or%a%noun%phrase?

Methods Does%the%method%name%suggest%why%it%would%be%called? Is%the%name%a%verb%or%a%verb%phrase?

Variables/Fields/Arguments Does%its%name%indicate%the%role%it's%playing? Does%the%length%of%the%name%reflect%its%scope?

Example I public List getThem() { List list1 = new ArrayList(); for (int[] x : theList) if (x[0] == 4) list1.add(x); return list1; } public List ListgetFlaggedCells() getFlaggedCells(){{ Listresult List flaggedCells = new ArrayList(); newArrayList(); ArrayList(); flaggedCells ==new for (Cell (int[]cell cell::gameBoard) gameBoard) if (cell.isFlagged()) (cell[STATUS_VALUE] == FLAGGED) result.add(cell); flaggedCells.add(cell); }

return result; flaggedCells;

Source: Clean Code: A Handbook of Agile Software Craftsmanship, Robert C. Martin, pages 18-19

Example 2 int s = 0; for (int j=0; j