Clean Code
5
A Handbook of Agile Software Craftsmanship
Robert C. Martin
Note by waegaein@github.com
Clean Code
The Total Cost of Owning a Mess
• Over the span of a year or two, teams that were moving very
fast at the beginning of a project can find themselves
moving at a snail’s pace.
The Total Cost of Owning a Mess
• Over the span of a year or two, teams that were moving very
fast at the beginning of a project can find themselves moving
at a snail’s pace.
• Every change they make to the code breaks two or three
other parts of the code.
The Total Cost of Owning a Mess
• Over the span of a year or two, teams that were moving very
fast at the beginning of a project can find themselves moving
at a snail’s pace.
• Every change they make to the code breaks two or three
other parts of the code.
• No change is trivial.
The Total Cost of Owning a Mess
• Over the span of a year or two, teams that were moving very
fast at the beginning of a project can find themselves moving
at a snail’s pace.
• Every change they make to the code breaks two or three
other parts of the code.
• No change is trivial.
• Every addition or modification to the system requires that the
tangles, twists, and knots be “understood” so that more
tangles, twists, and knots can be added.
The Total Cost of Owning a Mess
• As the mess build, the productivity of the team continues to
decrease.
The Total Cost of Owning a Mess
• As the mess build, the productivity of the team continues to
decrease.
• As productivity decreases, management does the only thing
they can; they add more staff to the project in hopes of
increasing productivity.
The Total Cost of Owning a Mess
• As the mess build, the productivity of the team continues to
decrease.
• As productivity decreases, management does the only thing
they can; they add more staff to the project in hopes of
increasing productivity.
• But that new staff is not versed in the design of the system.
The Total Cost of Owning a Mess
• Furthermore, they, and everyone else on the team, are under
horrific pressure to increase productivity.
The Total Cost of Owning a Mess
• Furthermore, they, and everyone else on the team, are under
horrific pressure to increase productivity.
• So they all make more and more messes, driving the
productivity ever further toward zero.
The Total Cost of Owning a Mess
Attitude
• Have you ever waded through a mess so grave that it took
weeks to do what should have taken hours?
Attitude
• Have you ever waded through a mess so grave that it took
weeks to do what should have taken hours?
• Have you seen what should have been a one-line change,
made instead in hundreds of different modules?
Attitude
• Have you ever waded through a mess so grave that it took
weeks to do what should have taken hours?
• Have you seen what should have been a one-line change,
made instead in hundreds of different modules?
• These symptoms are all too common.
Attitude
• Why does this happen to code?
Attitude
• Why does this happen to code?
• Why does good code rot so quickly into bad code?
Attitude
• We have lots of explanations for it.
Attitude
• We have lots of explanations for it.
• We complain that the requirements changed in ways that
thwart the original design.
Attitude
• We have lots of explanations for it.
• We complain that the requirements changed in ways that
thwart the original design.
• We bemoan the schedules that were too tight to do things
right.
Attitude
• We have lots of explanations for it.
• We complain that the requirements changed in ways that
thwart the original design.
• We bemoan the schedules that were too tight to do things
right.
• We blather about stupid managers and intolerant
customers and useless marketing types and telephone
sanitizers.
Attitude
• But the fault is not in our stars, but in ourselves.
Attitude
• But the fault is not in our stars, but in ourselves.
• We are unprofessional.
Attitude
“But wait!”
“If I don’t do what my manager says, I’ll be fired!”
Attitude
“But wait!”
“If I don’t do what my manager says, I’ll be fired!”
• Probably not.
Attitude
“But wait!”
“If I don’t do what my manager says, I’ll be fired!”
• Probably not.
• Most managers want the truth.
• Even when they don’t act like it.
Attitude
“But wait!”
“If I don’t do what my manager says, I’ll be fired!”
• Probably not.
• Most managers want the truth.
• Even when they don’t act like it.
• They may defend the schedule and requirements with
passion; but that’s their job.
Attitude
“But wait!”
“If I don’t do what my manager says, I’ll be fired!”
• Probably not.
• Most managers want the truth.
• Even when they don’t act like it.
• They may defend the schedule and requirements with
passion; but that’s their job.
• It’s your job to defend the code with equal passion.
Attitude
• A patient is complaining about doctor’s washing hands taking
too long.
Attitude
• A patient is complaining about doctor’s washing hands taking
too long.
• It would be unprofessional (never mind criminal) for the
doctor to comply with the patient and give up washing hands.
Attitude
• A patient is complaining about doctor’s washing hands taking
too long.
• It would be unprofessional (never mind criminal) for the
doctor to comply with the patient and give up washing hands.
• So too it is unprofessional for programmers to bend to the
will of managers who don’t understand the risks of making
messes.
The Boy Scout Rule
Leave the campground cleaner than you found it.

Clean Code - 5

  • 1.
    Clean Code 5 A Handbookof Agile Software Craftsmanship Robert C. Martin Note by waegaein@github.com
  • 2.
  • 3.
    The Total Costof Owning a Mess • Over the span of a year or two, teams that were moving very fast at the beginning of a project can find themselves moving at a snail’s pace.
  • 4.
    The Total Costof Owning a Mess • Over the span of a year or two, teams that were moving very fast at the beginning of a project can find themselves moving at a snail’s pace. • Every change they make to the code breaks two or three other parts of the code.
  • 5.
    The Total Costof Owning a Mess • Over the span of a year or two, teams that were moving very fast at the beginning of a project can find themselves moving at a snail’s pace. • Every change they make to the code breaks two or three other parts of the code. • No change is trivial.
  • 6.
    The Total Costof Owning a Mess • Over the span of a year or two, teams that were moving very fast at the beginning of a project can find themselves moving at a snail’s pace. • Every change they make to the code breaks two or three other parts of the code. • No change is trivial. • Every addition or modification to the system requires that the tangles, twists, and knots be “understood” so that more tangles, twists, and knots can be added.
  • 7.
    The Total Costof Owning a Mess • As the mess build, the productivity of the team continues to decrease.
  • 8.
    The Total Costof Owning a Mess • As the mess build, the productivity of the team continues to decrease. • As productivity decreases, management does the only thing they can; they add more staff to the project in hopes of increasing productivity.
  • 9.
    The Total Costof Owning a Mess • As the mess build, the productivity of the team continues to decrease. • As productivity decreases, management does the only thing they can; they add more staff to the project in hopes of increasing productivity. • But that new staff is not versed in the design of the system.
  • 10.
    The Total Costof Owning a Mess • Furthermore, they, and everyone else on the team, are under horrific pressure to increase productivity.
  • 11.
    The Total Costof Owning a Mess • Furthermore, they, and everyone else on the team, are under horrific pressure to increase productivity. • So they all make more and more messes, driving the productivity ever further toward zero.
  • 12.
    The Total Costof Owning a Mess
  • 13.
    Attitude • Have youever waded through a mess so grave that it took weeks to do what should have taken hours?
  • 14.
    Attitude • Have youever waded through a mess so grave that it took weeks to do what should have taken hours? • Have you seen what should have been a one-line change, made instead in hundreds of different modules?
  • 15.
    Attitude • Have youever waded through a mess so grave that it took weeks to do what should have taken hours? • Have you seen what should have been a one-line change, made instead in hundreds of different modules? • These symptoms are all too common.
  • 16.
    Attitude • Why doesthis happen to code?
  • 17.
    Attitude • Why doesthis happen to code? • Why does good code rot so quickly into bad code?
  • 18.
    Attitude • We havelots of explanations for it.
  • 19.
    Attitude • We havelots of explanations for it. • We complain that the requirements changed in ways that thwart the original design.
  • 20.
    Attitude • We havelots of explanations for it. • We complain that the requirements changed in ways that thwart the original design. • We bemoan the schedules that were too tight to do things right.
  • 21.
    Attitude • We havelots of explanations for it. • We complain that the requirements changed in ways that thwart the original design. • We bemoan the schedules that were too tight to do things right. • We blather about stupid managers and intolerant customers and useless marketing types and telephone sanitizers.
  • 22.
    Attitude • But thefault is not in our stars, but in ourselves.
  • 23.
    Attitude • But thefault is not in our stars, but in ourselves. • We are unprofessional.
  • 24.
    Attitude “But wait!” “If Idon’t do what my manager says, I’ll be fired!”
  • 25.
    Attitude “But wait!” “If Idon’t do what my manager says, I’ll be fired!” • Probably not.
  • 26.
    Attitude “But wait!” “If Idon’t do what my manager says, I’ll be fired!” • Probably not. • Most managers want the truth. • Even when they don’t act like it.
  • 27.
    Attitude “But wait!” “If Idon’t do what my manager says, I’ll be fired!” • Probably not. • Most managers want the truth. • Even when they don’t act like it. • They may defend the schedule and requirements with passion; but that’s their job.
  • 28.
    Attitude “But wait!” “If Idon’t do what my manager says, I’ll be fired!” • Probably not. • Most managers want the truth. • Even when they don’t act like it. • They may defend the schedule and requirements with passion; but that’s their job. • It’s your job to defend the code with equal passion.
  • 29.
    Attitude • A patientis complaining about doctor’s washing hands taking too long.
  • 30.
    Attitude • A patientis complaining about doctor’s washing hands taking too long. • It would be unprofessional (never mind criminal) for the doctor to comply with the patient and give up washing hands.
  • 31.
    Attitude • A patientis complaining about doctor’s washing hands taking too long. • It would be unprofessional (never mind criminal) for the doctor to comply with the patient and give up washing hands. • So too it is unprofessional for programmers to bend to the will of managers who don’t understand the risks of making messes.
  • 32.
    The Boy ScoutRule Leave the campground cleaner than you found it.