Jf 10 97ThingsEveryProgrammerShouldKnow
Transcript of Jf 10 97ThingsEveryProgrammerShouldKnow
8/18/2019 Jf 10 97ThingsEveryProgrammerShouldKnow
http://slidepdf.com/reader/full/jf-10-97thingseveryprogrammershouldknow 1/27
97 Things EveryProgrammerShould Know
http :/ / p rog ra m m e r.97th ing s.o re illy.c o m
@97TEPSK
Kevlin Henneyk e vl in@c urb ra la n .c o m
@Ke v linHe nne y
8/18/2019 Jf 10 97ThingsEveryProgrammerShouldKnow
http://slidepdf.com/reader/full/jf-10-97thingseveryprogrammershouldknow 2/27
8/18/2019 Jf 10 97ThingsEveryProgrammerShouldKnow
http://slidepdf.com/reader/full/jf-10-97thingseveryprogrammershouldknow 3/27
Adrian WibleAlan GriffithsAlex MillerAllan KellyAnders NoråsAnn Katrin GagnatAslam KhanBurk HufnagelCal EvansCarroll RobinsonCay HorstmannChuck AllisonClint Shank Dan Bergh JohnssonDan NorthDaniel LindnerDiomidisSpinellisEdward GarsonEinarLandreFilip van LaenenGerard MeszarosGiles ColborneGiovanni AsproniGreg ColvinGregorHohpe
Gudny HauknesHeinz Kabutz
Jan Christiaan "JC" van Winkel Janet Gregory Jason P Sage Johannes Brodwall Jon Jagger Jørn ØlmheimKari RøsslandKarianne BergKeith BraithwaiteKevlin HenneyKirk PepperdineKlaus MarquardtLinda RisingMarcus BakerMatt DoarMattiasKarlssonMichael FeathersMichael HungerMike LewisNate J acksonNeal FordNiclas NilssonOlve Maudal
Paul W Homer Pete GoodliffePeter SommerladRajith AttapattuRandy StaffordRichard Monson-HaefelRobert C Martin (Uncle Bob)Rod BegbieRussel WinderRyan BrushSam SaaristeSarah MountScott MeyersSeb RoseSteve Berczuk Steve FreemanSteve SmithThomas GuestUdi DahanVerity StobWalter Bright
YechielKimchi Yuriy Zubarev
8/18/2019 Jf 10 97ThingsEveryProgrammerShouldKnow
http://slidepdf.com/reader/full/jf-10-97thingseveryprogrammershouldknow 4/27
8/18/2019 Jf 10 97ThingsEveryProgrammerShouldKnow
http://slidepdf.com/reader/full/jf-10-97thingseveryprogrammershouldknow 5/27
8/18/2019 Jf 10 97ThingsEveryProgrammerShouldKnow
http://slidepdf.com/reader/full/jf-10-97thingseveryprogrammershouldknow 6/27
8/18/2019 Jf 10 97ThingsEveryProgrammerShouldKnow
http://slidepdf.com/reader/full/jf-10-97thingseveryprogrammershouldknow 7/27
Do Lots of Deliberate PracticeJo n Ja g g e r
You do deliberate practice to improve your ability to perform a
task. It’s about skill and technique. Deliberate practice meansrepetition. It means performing the task with the aim ofincreasing your mastery of one or more aspects of the task. Itmeans repeating the repetition. Slowly, over and over again,until you achieve your desired level of mastery. You dodeliberate practice to master the task, not to complete the task.
8/18/2019 Jf 10 97ThingsEveryProgrammerShouldKnow
http://slidepdf.com/reader/full/jf-10-97thingseveryprogrammershouldknow 8/27
Learn to EstimateG io va nn i A sp ro n i
An estimate is an approximate calculation or judgement of thevalue, number, quantity, or extent of something. This definitionimplies that [...] hopes and wishes must be ignored whencalculating it. The definition also implies that, beingapproximate, an estimate cannot be precise, e.g., adevelopment task cannot be estimated to last 234.14 days.A target is a statement of a desirable business objective, e.g.,“The system must support at least 400 concurrent users.”A commitment is a promise to deliver specified functionality ata certain level of quality by a certain date or event.
8/18/2019 Jf 10 97ThingsEveryProgrammerShouldKnow
http://slidepdf.com/reader/full/jf-10-97thingseveryprogrammershouldknow 9/27
Know Your Next CommitDa n Be rg h Jo hn sso n
I tapped three programmers on their shoulders and asked what they were doing.“I am refactoring these methods,” the first answered. “I am adding someparameters to this web action,” the second answered. The third answered, “I amworking on this user story.”It might seem that the first two were engrossed in the details of their work,while only the third could see the bigger picture, and that he had the betterfocus. However, when I asked when and what they would commit, the picture
changed dramatically. The first two were pretty clear about what files would beinvolved, and would be finished within an hour or so. The third programmeranswered, “Oh, I guess I will be ready within a few days. I will probably add afew classes and might change those services in some way.”
8/18/2019 Jf 10 97ThingsEveryProgrammerShouldKnow
http://slidepdf.com/reader/full/jf-10-97thingseveryprogrammershouldknow 10/27
Comment Only What theCode Cannot SayKe vl in He nne y
1. If a program is incorrect, it matters little what the documentation says.
2. If documentation does not agree with the code, it is not worth much.3. Consequently, code must largely document itself. If it cannot,
rewrite the code rather than increase the supplementary documentation. Good code needs fewer comments than bad code does.
4. Comments
should provide
additional
information
that
is
not
readily
obtainable from the code itself. They should never parrot the code.
5. Mnemonic variable names and labels, and a layout that emphasizes logical structure, help make a program self ‐ documenting.
Kernighan and PlaugerThe Elements of Programming Style
8/18/2019 Jf 10 97ThingsEveryProgrammerShouldKnow
http://slidepdf.com/reader/full/jf-10-97thingseveryprogrammershouldknow 11/27
Code in the Language ofthe DomainDa n N o rth
Phillip Calçadohttp://fragmental.tw/2009/04/29/tag-clouds-see-how-noisy-your-code-is/
8/18/2019 Jf 10 97ThingsEveryProgrammerShouldKnow
http://slidepdf.com/reader/full/jf-10-97thingseveryprogrammershouldknow 12/27
Encapsulate Behavior,Not Just StateEina r La nd re
An object encapsulates both state and behavior, wherethe behavior is defined by the actual state. [...]This inherent property of an object makes the design
process conceptually simple. It boils down to twosimple tasks: allocation and delegation ofresponsibility to the different objects including theinterobject interaction protocols.
8/18/2019 Jf 10 97ThingsEveryProgrammerShouldKnow
http://slidepdf.com/reader/full/jf-10-97thingseveryprogrammershouldknow 13/27
Don't Repeat Yourself Ste v e Sm ith
Duplication Is Waste
Repetition in Process Callsfor Automation
Repetition in Logic Callsfor Abstraction
8/18/2019 Jf 10 97ThingsEveryProgrammerShouldKnow
http://slidepdf.com/reader/full/jf-10-97thingseveryprogrammershouldknow 14/27
Beware the ShareUd i Da h a n
The fact that two wildly different parts of the system
performed some logic in the same way meant less than Ithought. Up until I had pulled out those libraries of sharedcode these parts were not dependent on each other. Each couldevolve independently. Each could change its logic to suit theneeds of the system’s changing business environment. Thosefour lines of similar code were accidental—a temporalanomaly a coincidence. That is until I came along.
8/18/2019 Jf 10 97ThingsEveryProgrammerShouldKnow
http://slidepdf.com/reader/full/jf-10-97thingseveryprogrammershouldknow 15/27
The Road to Performance IsLittered with Dirty Code BombsKirk Pe p p e rd ine
MORE OFTEN THAN NOT, PERFORMANCETUNING A SYSTEM REQUIRES YOU TO ALTERCODE. WHEN WE NEED TO ALTER CODE,
EVERY CHUNK THAT IS OVERLY COMPLEX ORHIGHLY COUPLED IS A DIRTY CODE BOMB
LYING IN WAIT TO DERAIL THE EFFORT. THEFIRST CASUALTY OF DIRTY CODE WILL BE
YOUR SCHEDULE.
8/18/2019 Jf 10 97ThingsEveryProgrammerShouldKnow
http://slidepdf.com/reader/full/jf-10-97thingseveryprogrammershouldknow 16/27
Act with PrudenceSe b Ro se
Martin Fowler http://martinfowler.com/bliki/TechnicalDebtQuadrant.html
8/18/2019 Jf 10 97ThingsEveryProgrammerShouldKnow
http://slidepdf.com/reader/full/jf-10-97thingseveryprogrammershouldknow 17/27
The Boy Scout RuleRo b e rt C M a rtin (Unc le Bo b )
Try and leave this world a littlebetter than you found it.
Robert Stephenson Smyth Baden-Powell
8/18/2019 Jf 10 97ThingsEveryProgrammerShouldKnow
http://slidepdf.com/reader/full/jf-10-97thingseveryprogrammershouldknow 18/27
Apply FunctionalProgramming PrinciplesEd w a rd G a rso n
An expression is said to be referentially transparent if it can be
replaced with its value without changing the program (in other words,yielding a program that has the same effects and output on the sameinput). [...]
The importance of referential transparency is that it allows a
programmer (or compiler) to reason about program behavior. This canhelp in proving correctness, simplifying an algorithm, assisting inmodifying code without breaking it, or optimizing code by means ofmemoization, common subexpression elimination or parallelization.
http://en.wikipedia.org/wiki/Referential_transparency_ computer_science)
8/18/2019 Jf 10 97ThingsEveryProgrammerShouldKnow
http://slidepdf.com/reader/full/jf-10-97thingseveryprogrammershouldknow 19/27
Thinking in StatesNic la s Nilsso n
People in the real world have a weirdrelationship with state.
In most real-world situations people’s
relaxed attitude toward state is not anissue. Unfortunately however manyprogrammers are quite vague about statetoo — and that is a problem.
8/18/2019 Jf 10 97ThingsEveryProgrammerShouldKnow
http://slidepdf.com/reader/full/jf-10-97thingseveryprogrammershouldknow 20/27
Two Wrongs Can Make a Right(and Are Difficult to Fix)A lla n Ke lly
8/18/2019 Jf 10 97ThingsEveryProgrammerShouldKnow
http://slidepdf.com/reader/full/jf-10-97thingseveryprogrammershouldknow 21/27
Code ReviewsM a ttia s Ka rlsso n
Making code reviews fun is perhaps the mostimportant contributor to success. Reviews are
about the people reviewing. If the review meetingis painful or dull, it will be hard to motivate
anyone. Make it an informal code review whoseprincipal purpose is to share knowledge among
team members. Leave sarcastic comments outside,
and bring a cake or brown-bag lunch instead.
8/18/2019 Jf 10 97ThingsEveryProgrammerShouldKnow
http://slidepdf.com/reader/full/jf-10-97thingseveryprogrammershouldknow 22/27
Testing Is the Engineering Rigorof Software DevelopmentNe a l Fo rd
Testing “hard” things is tough because youhave to build them to test them, which
discourages speculative building just to seewhat will happen. But the building processin software is ridiculously cheap.
8/18/2019 Jf 10 97ThingsEveryProgrammerShouldKnow
http://slidepdf.com/reader/full/jf-10-97thingseveryprogrammershouldknow 23/27
Write Tests for PeopleG e ra rd M e sza ro s
So w should you be writing the tests for? For theperson trying to understand your code.
Good tests act as documentation for the code they aretesting. They describe how the code works. For eachusage scenario, the test s):o Describe the context, starting point, or
preconditions that must be satisfiedo
Illustrate how the software is invokedo Describe the expected results or postconditions to
be verified
Different usage scenarios will have slightly different
versions of each of these.
8/18/2019 Jf 10 97ThingsEveryProgrammerShouldKnow
http://slidepdf.com/reader/full/jf-10-97thingseveryprogrammershouldknow 24/27
Don't Be Cute with YourTest DataRo d Be g b ie
8/18/2019 Jf 10 97ThingsEveryProgrammerShouldKnow
http://slidepdf.com/reader/full/jf-10-97thingseveryprogrammershouldknow 25/27
Ask "What Would the User Do?"(You Are Not the User)G ile s C o lb o rne
We all tend to assume that other people think like us. Butthey don't. Psychologists call this the false consensus bias.This bias explains why programmers have such a hardtime putting themselves in the users' position. Users don'tthink like programmers.The best way to find out how a user thinks is to watch one.
8/18/2019 Jf 10 97ThingsEveryProgrammerShouldKnow
http://slidepdf.com/reader/full/jf-10-97thingseveryprogrammershouldknow 26/27
Ubuntu Coding for Your FriendsA sla m Kha n
Umuntu ngumuntu ngabantu
8/18/2019 Jf 10 97ThingsEveryProgrammerShouldKnow
http://slidepdf.com/reader/full/jf-10-97thingseveryprogrammershouldknow 27/27
The newest computer can merely compound, at speed,the oldest problem in the relations between humanbeings, and in the end the communicator will beconfronted with the old problem, of what to say andhow to say it.
Edward R Murrow