Does Good Code
    Matter?
    Gian Lorenzetto
Implementation
               Patterns
                                   By Kent Beck

•   157 Pages / 77 Implementation ...
This book is not ...
• Not a style guide
• Not a design book
• Not a patterns book (!?)
• Not a language guide
• Not for b...
This book is ...
•   About writing good code for others -

    •   to read, to understand, to learn from and to
        ex...
Premise
• “I have seen too much ugly code make too
  much money to believe that quality of code
  is either necessary or s...
Book Overview
                       Introduction
                      • Patterns
                      • Values & Princi...
1. Introduction
• Overview
• Question minute-to-minute decisions
 • Why am I so sure this method should be
    called foo?...
Implementation
                     Patterns
                    Every few
                     seconds

Design Pattern   ...
2. Patterns
•   Programming laws (forces)
    1. Read more often than written
    2. No such thing as done
    3. Structur...
3. A Theory of Programming

• Values
 • Over-arching universal themes of
    programming
 • Communication, Simplicity, Fle...
3. A Theory of Programming


                 Principles
  Values                         Patterns

             Translate...
3. A Theory of Programming

• Principles
 • Local consequences
 • Minimize repetition
 • Logic and data together
 • Symmet...
4. Motivation

• cost = cost
       total     develop+ cost
                             maintain

• Increase up front cos...
5. Class
• Bundles related state
 • Class
 • Simple Superclass Name
 • Interface
 • Value Object
 • Inner Class
 • Conditi...
6. State

• Communicate use of state
• Objects package:
 • Behaviour (presented to outside world)
 • State (supports behav...
6. State
• Patterns
 • Access (Direct, Indirect)
 • State (Common,Variable, Extrinsic)
 • Variable (Local, Field, Paramete...
The best intentions ...
  x = 10;

  setX(10);

  openGarageDoor(10);

  openGarageDoor() {
     setX(10);
  }
7. Behaviour
• How to express behaviour of a program
 • Control Flow
 • Message (Choosing, Double Dispatch,
    Reversing,...
Guards, Guards!
void initialise() {               void initialise() {
  if (!isInitialised()) {           if (isInitialise...
8. Methods
• Why divide logic into chunks?
 • Readability, critical flow, understanding,
    communication ...
• Logic into...
8. Methods
•   Deciding what goes where is hard

    •   Compose Method

    •   Intention-Revealing Name

    •   Method ...
9. Collections
•   Patterns

    •   Metaphors

    •   Issues

    •   Interfaces (Array, Iterable, Collection ...)

    ...
Example ...
              stripHeader();
Attempt 1     stripFooter();
              process();



              strip???()...
The End
Upcoming SlideShare
Loading in …5
×

Mpg Feb08 Gian Lorenzetto

442 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
442
On SlideShare
0
From Embeds
0
Number of Embeds
27
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Mpg Feb08 Gian Lorenzetto

  1. 1. Does Good Code Matter? Gian Lorenzetto
  2. 2. Implementation Patterns By Kent Beck • 157 Pages / 77 Implementation Patterns • Not a “patterns” book • Java programming habits for creating readable code • Conscious approach • what do I want to tell the reader about this code? • what does the code communicate what I am thinking to others?
  3. 3. This book is not ... • Not a style guide • Not a design book • Not a patterns book (!?) • Not a language guide • Not for beginners (despite what Amazon thinks ...)
  4. 4. This book is ... • About writing good code for others - • to read, to understand, to learn from and to extend • For those who think life is too short to waste on bad code • For those who delight in writing beautiful code • Like spending a few hours inside Kent Beck’s head while he’s hacking JUnit
  5. 5. Premise • “I have seen too much ugly code make too much money to believe that quality of code is either necessary or sufficient for commercial success or wide-spread use.” • Communication - “ ... programming so other people can understand your code.” • Does good code matter?
  6. 6. Book Overview Introduction • Patterns • Values & Principles • Motivation Similar Logic Class Different Data Behavior State Dividing Logic Multi-Valued Data Methods Collections Frameworks
  7. 7. 1. Introduction • Overview • Question minute-to-minute decisions • Why am I so sure this method should be called foo? • Program consciously, for others • Format - essays, diagrams, teaching story, examples
  8. 8. Implementation Patterns Every few seconds Design Pattern Language Guide Few per day Why choose a Regulate object particular interaction construct?
  9. 9. 2. Patterns • Programming laws (forces) 1. Read more often than written 2. No such thing as done 3. Structured using basic set of state and control flow concepts 4. Readers need to understand in detail and in concept • Patterns illustrate a point of view about the relative priorities of these forces
  10. 10. 3. A Theory of Programming • Values • Over-arching universal themes of programming • Communication, Simplicity, Flexibility • Principles • Bridge the values
  11. 11. 3. A Theory of Programming Principles Values Patterns Translate motive Motivation What to do into action
  12. 12. 3. A Theory of Programming • Principles • Local consequences • Minimize repetition • Logic and data together • Symmetry • Declarative expression • Rate-of-change
  13. 13. 4. Motivation • cost = cost total develop+ cost maintain • Increase up front costs does not help • Implementation patterns satisfy human and economic needs
  14. 14. 5. Class • Bundles related state • Class • Simple Superclass Name • Interface • Value Object • Inner Class • Conditional
  15. 15. 6. State • Communicate use of state • Objects package: • Behaviour (presented to outside world) • State (supports behaviour) • Objects make analysing state easier
  16. 16. 6. State • Patterns • Access (Direct, Indirect) • State (Common,Variable, Extrinsic) • Variable (Local, Field, Parameter) • Role Suggesting Name • Declared Type • Initialisation (Eager, Lazy)
  17. 17. The best intentions ... x = 10; setX(10); openGarageDoor(10); openGarageDoor() { setX(10); }
  18. 18. 7. Behaviour • How to express behaviour of a program • Control Flow • Message (Choosing, Double Dispatch, Reversing, Inviting, Explaining) • Guard Clause • Exception
  19. 19. Guards, Guards! void initialise() { void initialise() { if (!isInitialised()) { if (isInitialised()) { ... return; } } } ... } • One entry point, one exit point • Express simple and local exceptional situations with purely local consequences • Highlight the difference between normal and exceptional processing
  20. 20. 8. Methods • Why divide logic into chunks? • Readability, critical flow, understanding, communication ... • Logic into methods Communicate • Methods into classes connection of logic • Classes into packages
  21. 21. 8. Methods • Deciding what goes where is hard • Compose Method • Intention-Revealing Name • Method Visibility • Method Object • Collection Accessor • Query Method • Setting Method
  22. 22. 9. Collections • Patterns • Metaphors • Issues • Interfaces (Array, Iterable, Collection ...) • Implementations (Collection, List, Set, Map) • Collections (Searching, Sorting, Unmodiiable, Single Element, Empty) • Extending Collections
  23. 23. Example ... stripHeader(); Attempt 1 stripFooter(); process(); strip???(); Attempt 2 process(); findTableElement(); Attempt 3 process();
  24. 24. The End

×