SlideShare a Scribd company logo
1 of 24
Download to read offline
Does Good Code
    Matter?
    Gian Lorenzetto
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?
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 ...)
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
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?
Book Overview
                       Introduction
                      • Patterns
                      • Values & Principles
                      • Motivation
  Similar Logic             Class                Different Data


Behavior                                               State
     Dividing Logic                           Multi-Valued Data

Methods                                            Collections
                       Frameworks
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
Implementation
                     Patterns
                    Every few
                     seconds

Design Pattern                     Language Guide

 Few per day
                  Why choose a
Regulate object
                   particular
  interaction
                   construct?
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
3. A Theory of Programming

• Values
 • Over-arching universal themes of
    programming
 • Communication, Simplicity, Flexibility
• Principles
 • Bridge the values
3. A Theory of Programming


                 Principles
  Values                         Patterns

             Translate motive
Motivation                      What to do
                into action
3. A Theory of Programming

• Principles
 • Local consequences
 • Minimize repetition
 • Logic and data together
 • Symmetry
 • Declarative expression
 • Rate-of-change
4. Motivation

• cost = cost
       total     develop+ cost
                             maintain

• Increase up front costs does not help
• Implementation patterns satisfy human and
  economic needs
5. Class
• Bundles related state
 • Class
 • Simple Superclass Name
 • Interface
 • Value Object
 • Inner Class
 • Conditional
6. State

• Communicate use of state
• Objects package:
 • Behaviour (presented to outside world)
 • State (supports behaviour)
• Objects make analysing state easier
6. State
• Patterns
 • Access (Direct, Indirect)
 • State (Common,Variable, Extrinsic)
 • Variable (Local, Field, Parameter)
 • Role Suggesting Name
 • Declared Type
 • Initialisation (Eager, Lazy)
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, Inviting, Explaining)
 • Guard Clause
 • Exception
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
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
8. Methods
•   Deciding what goes where is hard

    •   Compose Method

    •   Intention-Revealing Name

    •   Method Visibility

    •   Method Object

    •   Collection Accessor

    •   Query Method

    •   Setting Method
9. Collections
•   Patterns

    •   Metaphors

    •   Issues

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

    •   Implementations (Collection, List, Set, Map)

    •   Collections (Searching, Sorting, Unmodiiable,
        Single Element, Empty)

    •   Extending Collections
Example ...
              stripHeader();
Attempt 1     stripFooter();
              process();



              strip???();
Attempt 2     process();




              findTableElement();
Attempt 3     process();
The End

More Related Content

Similar to Mpg Feb08 Gian Lorenzetto

Code Quality Makes Your Job Easier
Code Quality Makes Your Job EasierCode Quality Makes Your Job Easier
Code Quality Makes Your Job EasierTonya Mork
 
Scripting Recipes for Testers
Scripting Recipes for TestersScripting Recipes for Testers
Scripting Recipes for TestersAdam Goucher
 
Designing Tag Navigation
Designing Tag NavigationDesigning Tag Navigation
Designing Tag Navigationadunne
 
Designing Tag Navigation
Designing Tag NavigationDesigning Tag Navigation
Designing Tag Navigationadunne
 
From Inspiration to Activation: Making Online Collaborative Communities Work
From Inspiration to Activation: Making Online Collaborative Communities WorkFrom Inspiration to Activation: Making Online Collaborative Communities Work
From Inspiration to Activation: Making Online Collaborative Communities WorkCommunitySense
 
Portfolios in Higher Education: Capitalizing on the Digital and Interactive
Portfolios in Higher Education: Capitalizing on the Digital and Interactive Portfolios in Higher Education: Capitalizing on the Digital and Interactive
Portfolios in Higher Education: Capitalizing on the Digital and Interactive dcambrid
 
Meditations/Metadata in an Emergency
Meditations/Metadata in an EmergencyMeditations/Metadata in an Emergency
Meditations/Metadata in an Emergencykramsey
 
Crafty communications - Dealing with the pesky people parts of communications
Crafty communications - Dealing with the pesky people parts of communicationsCrafty communications - Dealing with the pesky people parts of communications
Crafty communications - Dealing with the pesky people parts of communicationsAsher Glynn
 
Writing Readable Code
Writing Readable CodeWriting Readable Code
Writing Readable Codeeddiehaber
 
Programming Language Selection
Programming Language SelectionProgramming Language Selection
Programming Language SelectionDhananjay Nene
 
Understanding The Voice Of Your Customer
Understanding The Voice Of Your CustomerUnderstanding The Voice Of Your Customer
Understanding The Voice Of Your CustomerMichael Hirt
 
Javascript Framework Roundup FYB
Javascript Framework Roundup FYBJavascript Framework Roundup FYB
Javascript Framework Roundup FYBnukeevry1
 
Replacing Teachers with Crowds
Replacing Teachers with CrowdsReplacing Teachers with Crowds
Replacing Teachers with Crowdsjondron
 
People-Centered Design
People-Centered DesignPeople-Centered Design
People-Centered DesignKatrina Alcorn
 
Modern Webdevelopment With Ruby On Rails
Modern Webdevelopment With Ruby On RailsModern Webdevelopment With Ruby On Rails
Modern Webdevelopment With Ruby On RailsRobert Glaser
 
Reading Presentation Tai Tokerau 2009
Reading Presentation Tai Tokerau 2009Reading Presentation Tai Tokerau 2009
Reading Presentation Tai Tokerau 2009Scotty Delemare
 

Similar to Mpg Feb08 Gian Lorenzetto (20)

Code Quality Makes Your Job Easier
Code Quality Makes Your Job EasierCode Quality Makes Your Job Easier
Code Quality Makes Your Job Easier
 
Scripting Recipes for Testers
Scripting Recipes for TestersScripting Recipes for Testers
Scripting Recipes for Testers
 
Designing Tag Navigation
Designing Tag NavigationDesigning Tag Navigation
Designing Tag Navigation
 
Designing Tag Navigation
Designing Tag NavigationDesigning Tag Navigation
Designing Tag Navigation
 
From Inspiration to Activation: Making Online Collaborative Communities Work
From Inspiration to Activation: Making Online Collaborative Communities WorkFrom Inspiration to Activation: Making Online Collaborative Communities Work
From Inspiration to Activation: Making Online Collaborative Communities Work
 
Portfolios in Higher Education: Capitalizing on the Digital and Interactive
Portfolios in Higher Education: Capitalizing on the Digital and Interactive Portfolios in Higher Education: Capitalizing on the Digital and Interactive
Portfolios in Higher Education: Capitalizing on the Digital and Interactive
 
Becoming A Php Ninja
Becoming A Php NinjaBecoming A Php Ninja
Becoming A Php Ninja
 
Ontologies
OntologiesOntologies
Ontologies
 
Writersworld
WritersworldWritersworld
Writersworld
 
Meditations/Metadata in an Emergency
Meditations/Metadata in an EmergencyMeditations/Metadata in an Emergency
Meditations/Metadata in an Emergency
 
Week7
Week7Week7
Week7
 
Crafty communications - Dealing with the pesky people parts of communications
Crafty communications - Dealing with the pesky people parts of communicationsCrafty communications - Dealing with the pesky people parts of communications
Crafty communications - Dealing with the pesky people parts of communications
 
Writing Readable Code
Writing Readable CodeWriting Readable Code
Writing Readable Code
 
Programming Language Selection
Programming Language SelectionProgramming Language Selection
Programming Language Selection
 
Understanding The Voice Of Your Customer
Understanding The Voice Of Your CustomerUnderstanding The Voice Of Your Customer
Understanding The Voice Of Your Customer
 
Javascript Framework Roundup FYB
Javascript Framework Roundup FYBJavascript Framework Roundup FYB
Javascript Framework Roundup FYB
 
Replacing Teachers with Crowds
Replacing Teachers with CrowdsReplacing Teachers with Crowds
Replacing Teachers with Crowds
 
People-Centered Design
People-Centered DesignPeople-Centered Design
People-Centered Design
 
Modern Webdevelopment With Ruby On Rails
Modern Webdevelopment With Ruby On RailsModern Webdevelopment With Ruby On Rails
Modern Webdevelopment With Ruby On Rails
 
Reading Presentation Tai Tokerau 2009
Reading Presentation Tai Tokerau 2009Reading Presentation Tai Tokerau 2009
Reading Presentation Tai Tokerau 2009
 

More from melbournepatterns (20)

An Introduction to
An Introduction to An Introduction to
An Introduction to
 
State Pattern from GoF
State Pattern from GoFState Pattern from GoF
State Pattern from GoF
 
Iterator Pattern
Iterator PatternIterator Pattern
Iterator Pattern
 
Iterator
IteratorIterator
Iterator
 
Concurrency Patterns
Concurrency PatternsConcurrency Patterns
Concurrency Patterns
 
Continuous Integration, Fast Builds and Flot
Continuous Integration, Fast Builds and FlotContinuous Integration, Fast Builds and Flot
Continuous Integration, Fast Builds and Flot
 
Command Pattern
Command PatternCommand Pattern
Command Pattern
 
Code Contracts API In .Net
Code Contracts API In .NetCode Contracts API In .Net
Code Contracts API In .Net
 
LINQ/PLINQ
LINQ/PLINQLINQ/PLINQ
LINQ/PLINQ
 
Gpu Cuda
Gpu CudaGpu Cuda
Gpu Cuda
 
Facade Pattern
Facade PatternFacade Pattern
Facade Pattern
 
Phani Kumar - Decorator Pattern
Phani Kumar - Decorator PatternPhani Kumar - Decorator Pattern
Phani Kumar - Decorator Pattern
 
Composite Pattern
Composite PatternComposite Pattern
Composite Pattern
 
Adapter Design Pattern
Adapter Design PatternAdapter Design Pattern
Adapter Design Pattern
 
Prototype Design Pattern
Prototype Design PatternPrototype Design Pattern
Prototype Design Pattern
 
Factory Method Design Pattern
Factory Method Design PatternFactory Method Design Pattern
Factory Method Design Pattern
 
Abstract Factory Design Pattern
Abstract Factory Design PatternAbstract Factory Design Pattern
Abstract Factory Design Pattern
 
A Little Lisp
A Little LispA Little Lisp
A Little Lisp
 
State Pattern in Flex
State Pattern in FlexState Pattern in Flex
State Pattern in Flex
 
Active Object
Active ObjectActive Object
Active Object
 

Recently uploaded

Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsHyundai Motor Group
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 

Recently uploaded (20)

Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 

Mpg Feb08 Gian Lorenzetto

  • 1. Does Good Code Matter? Gian Lorenzetto
  • 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. 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. 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. 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. Book Overview Introduction • Patterns • Values & Principles • Motivation Similar Logic Class Different Data Behavior State Dividing Logic Multi-Valued Data Methods Collections Frameworks
  • 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. Implementation Patterns Every few seconds Design Pattern Language Guide Few per day Why choose a Regulate object particular interaction construct?
  • 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. 3. A Theory of Programming • Values • Over-arching universal themes of programming • Communication, Simplicity, Flexibility • Principles • Bridge the values
  • 11. 3. A Theory of Programming Principles Values Patterns Translate motive Motivation What to do into action
  • 12. 3. A Theory of Programming • Principles • Local consequences • Minimize repetition • Logic and data together • Symmetry • Declarative expression • Rate-of-change
  • 13. 4. Motivation • cost = cost total develop+ cost maintain • Increase up front costs does not help • Implementation patterns satisfy human and economic needs
  • 14. 5. Class • Bundles related state • Class • Simple Superclass Name • Interface • Value Object • Inner Class • Conditional
  • 15. 6. State • Communicate use of state • Objects package: • Behaviour (presented to outside world) • State (supports behaviour) • Objects make analysing state easier
  • 16. 6. State • Patterns • Access (Direct, Indirect) • State (Common,Variable, Extrinsic) • Variable (Local, Field, Parameter) • Role Suggesting Name • Declared Type • Initialisation (Eager, Lazy)
  • 17. The best intentions ... x = 10; setX(10); openGarageDoor(10); openGarageDoor() { setX(10); }
  • 18. 7. Behaviour • How to express behaviour of a program • Control Flow • Message (Choosing, Double Dispatch, Reversing, Inviting, Explaining) • Guard Clause • Exception
  • 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. 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. 8. Methods • Deciding what goes where is hard • Compose Method • Intention-Revealing Name • Method Visibility • Method Object • Collection Accessor • Query Method • Setting Method
  • 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. Example ... stripHeader(); Attempt 1 stripFooter(); process(); strip???(); Attempt 2 process(); findTableElement(); Attempt 3 process();