Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Developer on Detox

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
Tweet

More Decks by Michał Płachta

Other Decks in Programming

Transcript

  1. @miciek
    Michał Płachta
    Developer
    on
    DETOX
    www.michalplachta.com

    View Slide

  2. @miciek
    Meet John Craft

    View Slide

  3. @miciek
    John Learns… All The Time

    View Slide

  4. @miciek
    John Pair Programs

    View Slide

  5. @miciek
    John uses TDD

    View Slide

  6. @miciek
    John Monitors Tests Stability

    View Slide

  7. @miciek
    John Uses Simple Design
    Passes Tests
    Reveals Intention
    No Duplication
    Fewest Elements

    View Slide

  8. @miciek
    John Uses Monitoring

    View Slide

  9. @miciek
    John Loves Code Reviews

    View Slide

  10. @miciek
    John Cares About Cycle Time
    Idea Happy
    User

    View Slide

  11. @miciek
    John Is Software Craftsman

    View Slide

  12. @miciek
    John Aspires To Be An Artist
    2MB RAM

    View Slide

  13. @miciek
    vs
    Craftsman Artist

    View Slide

  14. @miciek
    vs vs
    Craftsman Artist Human

    View Slide

  15. @miciek
    The
    Friday’s
    Standup

    View Slide

  16. @miciek
    The Story Of The Story
    Standup
    Review
    Started

    View Slide

  17. @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

    View Slide

  18. @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

    View Slide

  19. @miciek
    Decision Paralysis

    View Slide

  20. @miciek
    John Uses Intuition

    View Slide

  21. @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!

    View Slide

  22. @miciek
    Illusion Of Confidence
    http://redonline.cdnds.net/main/thumbs/18472/george-clooney-dr-doug-er-pictures-tv-shows-redonline.co.uk.jpg

    View Slide

  23. @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%]

    View Slide

  24. @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

    View Slide

  25. @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

    View Slide

  26. @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

    View Slide

  27. @miciek
    Illusion Of Knowledge
    I use it
    every day!
    I know how
    it works!
    therefore

    View Slide

  28. @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

    View Slide

  29. @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/

    View Slide

  30. @miciek
    Illusion of Confidence
    +
    Illusion of Knowledge
    =
    Opinion

    View Slide

  31. @miciek
    Dealing With Illusions
    Why?
    Why?
    Why?
    Why?
    Why?

    View Slide

  32. @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?

    View Slide

  33. @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?

    View Slide

  34. @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?

    View Slide

  35. @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.

    View Slide

  36. @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.

    View Slide

  37. @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!

    View Slide

  38. @miciek
    John Was Under Influence of Illusions

    View Slide

  39. @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

    View Slide

  40. @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...”

    View Slide

  41. @miciek
    Any Alternatives?
    decisions based on data
    well-designed
    experiments
    evaluative
    research papers

    View Slide

  42. @miciek
    Agenda
    Intuition & Illusions Example: Names Example: Backlog
    DETOX
    before DETOX
    after

    View Slide

  43. @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

    View Slide

  44. @miciek
    Let’s Do Some Research!

    View Slide

  45. @miciek

    There are only two hard
    things in Computer Science:
    cache invalidation and
    naming things.
    - Phil Karlton

    View Slide

  46. @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

    View Slide

  47. @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%

    View Slide

  48. @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”

    View Slide

  49. @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”

    View Slide

  50. @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”

    View Slide

  51. @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?

    View Slide

  52. @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.

    View Slide

  53. @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”

    View Slide

  54. @miciek
    n1
    Identifier
    Names (N)
    Concepts
    (C)
    book to book
    a book
    number
    accountNumber
    an account
    number
    a phone
    number
    Homonyms & Synonyms

    View Slide

  55. @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

    View Slide

  56. @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

    View Slide

  57. @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”

    View Slide

  58. @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”

    View Slide

  59. @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”

    View Slide

  60. @miciek
    Being A Good Naming Craftsman
    one name per
    concept
    no homonyms no synonyms
    well defined
    abbreviations

    View Slide

  61. @miciek
    Being A Good Naming Craftsman
    one name per
    concept
    no homonyms no synonyms
    well defined
    abbreviations
    currently
    impossible!

    View Slide

  62. @miciek
    Being A Good Decent Naming Craftsman
    don’t pick on
    someone else’s
    names
    find & analyse
    existing names

    View Slide

  63. @miciek
    Agenda
    Intuition & Illusions Example: Names Example: Backlog
    DETOX
    before DETOX
    after

    View Slide

  64. @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

    View Slide

  65. @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

    View Slide

  66. @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

    View Slide

  67. @miciek
    iDoneThis case
    http://blog.idonethis.com/how-to-master-the-art-of-to-do-lists/
    Done List
    160,000
    users
    done to-do
    reported dones

    View Slide

  68. @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...

    View Slide

  69. @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

    View Slide

  70. @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

    View Slide

  71. @miciek
    Zeigarnik Effect
    https://pl.pinterest.com/pin/59250551327511553/

    View Slide

  72. @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

    View Slide

  73. @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

    View Slide

  74. @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

    View Slide

  75. @miciek
    Does It Work For Multiple Goals?
    NO!
    “...specific planning is
    less effective for multiple goals
    versus a single goal..”

    View Slide

  76. @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

    View Slide

  77. @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

    View Slide

  78. @miciek
    John Was Under Influence of Illusions

    View Slide

  79. @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...”

    View Slide

  80. @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…”

    View Slide

  81. @miciek
    John Did Some Research!
    don’t pick on
    someone else’s
    names
    find & analyse
    existing names

    View Slide

  82. @miciek
    John Did Some Research!
    don’t add
    things to
    backlog

    View Slide

  83. @miciek
    John Did Some Research!
    ■ read some papers
    ■ did some experiments
    ■ drew conclusions

    View Slide

  84. @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

    View Slide

  85. @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

    View Slide

  86. @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

    View Slide

  87. @miciek
    Thanks!
    Developer DETOX
    on
    ANY QUESTIONS?
    Michał Płachta
    www.michalplachta.com

    View Slide

  88. @miciek
    ~FIN~

    View Slide