Share
Embed
Developer on Detox
Let’s meet John Craft - a great software craftsman. Today is his last day at work before long holidays. John has just given his functionality to review and wants to leave at 6:00 PM.
This is a story of a code review, in which the reviewer found a few unfortunate issues at the worst possible time - 5 minutes before the holidays.
Let’s put ourselves in John’s shoes and try to decide what is the best solution for a true craftsman, who is interested in both quality and good design. I will talk about illusions, intuition, and decision making.
Michał Płachta
February 25, 2017
Transcript
88 slides
-
@miciek John Uses Simple Design Passes Tests Reveals Intention No
Duplication Fewest Elements -
@miciek What Would You Do? stay until names are fixed
ask the team to finish merge change add “fix names” to backlog leave and continue when you’re back -
@miciek vs vs Choice Craftsman Artist Human stay until names
are fixed leave continue when you’re back ask the team to finish merge change add “fix names” to backlog -
@miciek Doctor Satisfaction Chabris, Simons - “The Invisible Gorilla: How
Our Intuitions Deceive Us”, p. 106 Doctor A Doctor B Doctor C Doctor D said nothing expressed uncertainty “You have nothing to lose” consulted a book prescribed antibiotics prescribed antibiotics prescribed antibiotics prescribed antibiotics Lowest perceived satisfaction! OMG! He consulted a book! We’re doomed! -
@miciek Trivia Quiz Chabris, Simons - “The Invisible Gorilla: How
Our Intuitions Deceive Us”, p. 100 Question #1 True or False? Question #1 True or False? Question #1 True or False? Question #1 True or False? Question #1 True or False? Your Confidence [50-100%] -
@miciek Trivia Test Confidence Chabris, Simons - “The Invisible Gorilla:
How Our Intuitions Deceive Us”, p. 100 Question #1 True or False? Question #1 True or False? Question #1 True or False? Question #1 True or False? Question #1 True or False? Your Confidence [50-100%] 60% average correctness 75% average confidence -
@miciek Chabris, Simons - “The Invisible Gorilla: How Our Intuitions
Deceive Us”, p. 100 Few Weeks Later... A Second Test Different Questions 90% confident people were the same I have a confident character! but still only 60% average correctness -
@miciek “ Confidence appears to be a consistent quality [...]
that has relatively little to do with one’s knowledge or mental ability. - Chabris, Simons Chabris, Simons - “The Invisible Gorilla: How Our Intuitions Deceive Us”, p. 101 -
@miciek Illusion Of Knowledge I use it every day! I
know how it works! therefore -
@miciek Quiz: How Does It Work? ▪ car speed meter?
▪ zipper? ▪ toilet? ▪ piano key? ▪ sewing machine? ▪ bike? rate your understanding 1-7 Chabris, Simons - “The Invisible Gorilla: How Our Intuitions Deceive Us”, p. 120 -
@miciek How Does A Bike Work? 4.5/7 average reported understanding
https://www.dezeen.com/2016/06/19/velocipedia-project-hopeless-bicycle-drawings-life-digital-renders-gianluca-gimini/ -
@miciek Why Does Bike Work? Why? Why? Why? Why? Why?
Cyclist uses pedals to make the bike move and steering wheel to steer. Why do pedals make the bike move? -
@miciek Why Do Pedals Make The Bike Move? Why? Why?
Why? Why? Why? Pedals are connected with the chain drive which transmits the mechanical power and moves the wheels. Why do wheels move without falling? -
@miciek Why Do Wheels Move Without Falling? Why? Why? Why?
Why? Why? Thanks to the steering axis angle. Why is the steering axis angle so important? -
@miciek Why Is Steering Axis Angle So Important? Why? Why?
Why? Why? Why? Why don’t bikes fall when turning? http://www.fiztaszki.pl/node/56 Thanks to the trail. -
@miciek Why Don’t Bikes Fall When Turning? Why? Why? Why?
Why? Why? https://upload.wikimedia.org/wikipedia/commons/thumb/8/88/Tuftscriterium.jpg/728px-Tuftscriterium.jpg Thanks to the centrifugal force. -
@miciek Developer’s Opinions tests are very important standups should be
done every day open space are good for collaboration good names make the code readable Oh Yes! -
@miciek Developer DETOX on “ Whenever I make a decision
based on intuition, I state it openly and humbly. I am aware of my limitations. John - Humble Developer -
@miciek Developer DETOX on Doesn’t say ▪ “This is a
good practice…” ▪ “This is an antipattern…” ▪ “Uncle Bob said that…” ▪ “Everybody knows that…” ▪ “This is prerequisite for having a clean code...” ▪ “This is not advised...” -
@miciek Agenda Intuition & Illusions Example: Names Example: Backlog DETOX
before DETOX after -
@miciek What Would Developer On Detox Do? stay until names
are fixed ask the team to finish merge change add “fix names” to backlog leave and continue when you’re back -
@miciek “ There are only two hard things in Computer
Science: cache invalidation and naming things. - Phil Karlton -
@miciek The Good, The Bad and The Ugly... Name I
am writing the code “Names look good” I am reviewing someone’s code “Names look bad/ugly” …because it’s a prerequisite to understand the rest! …or I don’t pay attention because I am focusing on concepts & design -
@miciek Most Serious Problems LaToza, Venolia, DeLine - “Maintaining Mental
Models: A Study of Developer Work Habits” This is a serious problem for me % agree “Understanding the rationale behind a piece of code” 66% “Understanding code that someone else wrote” 56% “Understanding the history of a piece of code” 51% -
@miciek Most Serious Problems LaToza, Venolia, DeLine - “Maintaining Mental
Models: A Study of Developer Work Habits” This is a serious problem for me % agree “Understanding the rationale behind a piece of code” 66% “Understanding code that someone else wrote” 56% “Understanding the history of a piece of code” 51% 17% “Understanding a piece of code written by me” -
@miciek Names are ~70% Identifiers Keywords Delimiters Operators Literals 70%
30% (based on data from Eclipse 3.0M7, Tomcat 5.0.30, Sun JDK 1.4.2) / Deißenböck, Pizka - “Concise and Consistent Naming” -
@miciek Dealing With Naming Problem Robert Martin - “Clean Code”
“use intention-revealing names" “avoid disinformation" “make meaningful distinctions” “use pronounceable names” “use searchable names” “avoid encodings” “don't be cute” “don't pun” “pick one word per concept” “use solution domain names” “use problem domain names” “add meaningful context” -
@miciek Cargo Cult Of Naming Conventions intention-revealing avoid meaningful use
use avoid don't don't one word use use meaningful But what does meaningful even mean? -
@miciek Difference Of Opinion “ 7-18% chance that two people
apply the same name to an object* ...a name not only needs to be meaningful but reflect the correct meaning. Second, the “correct” meaning and name of a concept is naturally highly debatable. - Deißenböck, Pizka *G. Butler, P. Grogono, R. Shinghal, and I. Tjandra. Retrieving information from data flow diagrams. In Working Conference on Reverse Engineering, pages 84–93, November 1995. -
@miciek n1 Identifier Names (N) Concepts (C) n1 c1 c2
n2 Identifier Naming Formally ... all identifiers found in the source code ... all concepts related to the project & team R concept c1 is represented by n2 in the code Deißenböck, Pizka - “Concise and Consistent Naming” -
@miciek n1 Identifier Names (N) Concepts (C) book to book
a book number accountNumber an account number a phone number Homonyms & Synonyms -
@miciek n1 Identifier Names (N) Concepts (C) book reserve to
book reserve a book number phoneNumber accountNumber an account number a phone number Renaming and Code Decay -
@miciek Keeping Up With All The Names Deißenböck, Pizka -
“Concise and Consistent Naming” Project # identifiers # words Eclipse 3.0M7 94,829 7,233 Sun’s JDK 1.4.2 42,869 6,426 Tomcat 5.0.30 11,656 2,587 About half as much as Oxford Advanced Learner’s Dictionary examples: frag, fragement, fragment, fragmentation, fragmented, fragmentname, fragments, frags -
@miciek n1 Identifier Names (N) Concepts (C) reserve reserve book
phoneNumber accountNumber account number phone number Control The Concept Space! book Deißenböck, Pizka - “Concise and Consistent Naming” -
@miciek Pure Concepts As Names distance_between_abscissae = first_abscissa - second_abscissa
distance_between_ordinates = first_ordinate - second_ordinate cartesian_distance = square_root( distance_between_abscissae * distance_between_abscissae + distance_between_ordinates * distance_between_ordinates) Lawrie, Morrell - “Identifier length and limited programmer memory” -
@miciek Concept Can Be An Abbreviation distance_between_abscissae = first_abscissa -
second_abscissa distance_between_ordinates = first_ordinate - second_ordinate cartesian_distance = square_root( distance_between_abscissae * distance_between_abscissae + distance_between_ordinates * distance_between_ordinates) dx = x1 - x2 dy = y1 - y2 dist = sqrt(dx * dx + dy * dy) Concepts (C) dx dy dist x1 x2 y1 y2 Lawrie, Morrell - “Identifier length and limited programmer memory” -
@miciek Being A Good Naming Craftsman one name per concept
no homonyms no synonyms well defined abbreviations -
@miciek Being A Good Naming Craftsman one name per concept
no homonyms no synonyms well defined abbreviations currently impossible! -
@miciek Being A Good Decent Naming Craftsman don’t pick on
someone else’s names find & analyse existing names -
@miciek Agenda Intuition & Illusions Example: Names Example: Backlog DETOX
before DETOX after -
@miciek Backlog = To-Do List “ ...list of features or
technical tasks which the team maintains and which, at a given moment, are known to be necessary and sufficient to complete a project or a release. - Agile Alliance https://www.atlassian.com/agile/backlogs -
@miciek Dev’s To Do Dev’s To Do Stakeholders’ To-Do Dev’s
To Do User’s To Do PO’s To Do Team’s To Do Backlog -
@miciek Brain Dump Call Mom Jim’s flowers Take out trash
Do bank papers Buy lightbulbs Fix bug in X Fix flaky test Add Feature Z Refactor Y’s API Better names in X -
@miciek 85% dones were not to-do items Human vs Human’s
Plan 41% to-do items never completed http://blog.idonethis.com/how-to-master-the-art-of-to-do-lists/ 78% to-do items done within a day We suck at planning and there is no hope... -
@miciek Ocado Backlogs Project Total Items Never Done Never Done
% Pick Station 1337 637 47% Phoenix Core 1192 553 46% Decant 1013 437 43% Phoenix Outbound 1725 618 35% OSP RMS 379 105 27% Hawk 1763 395 22% Data gathered 6.02.2017 -
@miciek Why Do We Do That? 20-50% backlog items never
completed someone created them someone discussed them someone analysed them someone groomed them someone prioritised them someone deleted them -
@miciek Zeigarnik Intrusions Experiment Masicampo, Baumeister - “Consider It Done!
Plan Making Can Eliminate the Cognitive Effects of Unfulfilled Goals” Group #1 “Unfulfilled” Group #2 “Plan” Group #3 “Control” 2 important future tasks 2 important past tasks - make when, why, how plans - read 3,200 words answer questions about the text -
@miciek Zeigarnik Intrusions Masicampo, Baumeister - “Consider It Done! Plan
Making Can Eliminate the Cognitive Effects of Unfulfilled Goals” Group #1 “Unfulfilled” Group #2 “Plan” Group #3 “Control” ability to focus (1-7) 4.61 5.56 5.29 mind wanderings 65% 33% 50% reading comprehension 6.13 6.94 6.93 -
@miciek Masicampo, Baumeister - “Consider It Done! Plan Making Can
Eliminate the Cognitive Effects of Unfulfilled Goals” “Participants who reflected on two important but unfinished tasks were distracted…” “...forming a plan can eliminate cognitive activity from unfulfilled goal…” PLAN = how, when, and why to complete the goal -
@miciek Does It Work For Multiple Goals? NO! “...specific planning
is less effective for multiple goals versus a single goal..” -
@miciek Being A Backlog-aware Craftsman don’t add things to backlog
add only if you have a detailed plan add only if you’ll do it very soon -
@miciek John Had A Problem stay until names are fixed
ask the team to finish merge change add “fix names” to backlog leave and continue when you’re back -
@miciek Developer DETOX on Doesn’t say ▪ “This is a
good practice…” ▪ “This is an antipattern…” ▪ “Uncle Bob said that…” ▪ “Everybody knows that…” ▪ “This is prerequisite for having a clean code...” ▪ “This is not advised...” -
@miciek Developer DETOX on Says ▪ “Let me check the
research about…” ▪ “Let me do an experiment…” ▪ “Here’s data that supports my claim…” And... ▪ “I am sorry, I used my intuition here…” -
@miciek John Did Some Research! don’t pick on someone else’s
names find & analyse existing names -
@miciek John Did Some Research! ▪ read some papers ▪
did some experiments ▪ drew conclusions -
@miciek ▪ “Folklore and science of naming practices” http://michalplachta.com/2017/01/22/folklore-and-science-of-naming-practices/ ▪
“Quantifying Identifier Quality: An Analysis of Trends” Lawrie, Feild, Binkley http://www.cs.loyola.edu/~lawrie/papers/lawrieJese07.pdf ▪ “Concise and Consistent Naming” Deißenböck & Pizka http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.70.618&rank=1 ▪ “Clean Code: A Handbook of Agile Software Craftsmanship” Robert C. Martin ▪ “Maintaining Mental Models: A Study of Developer Work Habits” LaToza, Venolia, DeLine http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.111.2317&rank=1 ▪ “Identifier length and limited programmer memory” Binkley, Lawrie, Maex, Morrell ▪ “The effects of comments and identifier names on program comprehensibility: An experimental investigation” Takang, Grubb, Macredie ▪ “Effective Identifier Names for Comprehension and Memory” Lawrie, Morrell, Feild, Binkley References - Naming Research -
@miciek ▪ “What a To-Do: Studies of Task Management Towards
the Design of a Personal Task List Manager” Bellotti, Dalal, Good, Flynn, Bobrow. Ducheneaut ▪ “How to Master the Art of To-Do Lists by Understanding Why They Fail” http://blog.idonethis.com/how-to-master-the-art-of-to-do-lists/ ▪ “Consider It Done! Plan Making Can Eliminate the Cognitive Effects of Unfulfilled Goals” Masicampo, Baumeister ▪ “Too Much of a Good Thing: The Benefits of Implementation Intentions Depend on the Number of Goals” Dalton, Spiller ▪ “To-Do Lists Don’t Work” https://hbr.org/2012/01/to-do-lists-dont-work ▪ “The Scrum Backlog is where Features go to die” https://medium.com/product-love/the-scrum-backlog-is-where-features-go-to-die- b1336ff707aa References - Backlog Research -
@miciek ▪ “Velocipedia” https://www.dezeen.com/2016/06/19/velocipedia-project-hopeless-bicycle-dra wings-life-digital-renders-gianluca-gimini/ ▪ “The Invisible Gorilla: How
Our Intuitions Deceive Us” Chabris, Simons References - Intuition Research