SlideShare uma empresa Scribd logo
1 de 30
Baixar para ler offline
Object Calisthenics
October 2016
Peter Kofler, ‘Code Cop’
@codecopkofler
www.code-cop.org
Copyright Peter Kofler, licensed under CC-BY.
Peter Kofler
• Ph.D. (Appl. Math.)
• Professional Software
Developer for 15+ years
• “fanatic about code quality”
• Freelance Code Mentor
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
I help development teams with
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
●
Professionalism
●
Quality and
Productivity
●
Continuous
Improvement
Mentoring
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
●
Pair Programming
●
Programming
Workshops
●
Deliberate
Practice, e.g.
Coding Dojos
Developing Quality
Software Developers
Agenda
●
Concepts of OO
●
Encapsulation
●
Coupling and
Cohesion
●
Coding Exercise
“Object Calisthenics”
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
Discussion
●
What is Object Orientation?
●
What are its
basic features?
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
OOP is based on
●
Abstraction
●
Encapsulation
●
Polymorphy
●
Inheritance
●
Coupling
●
Cohesion
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
Abstraction
●
“A class should capture one and only
one key abstraction.”
●
Avoid Primitive Obsession.
●
Single Responsibility Principle (SRP).
●
Wrap All Primitives And Strings. (OC#3)
●
First Class Collections. (OC#4)
●
Keep All Entities Small. (OC#7)
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
Encapsulation
●
“Objects are defined by what they do, not
what they contain.“
●
All data should be hidden within its class.
●
Tell, Don't Ask.
●
e.g.
●
All fields must be private.
●
No Getters/Setters/Properties. (OC#9)
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
Polymorphy
●
Avoid switch statements (Type Code).
●
“Explicit case on the type of an object
(instanceof) is usually an error.”
●
Open Closed Principle (OCP).
●
e.g.
●
Avoid switch statements.
●
Don’t Use The else Keyword. (OC#2)
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
Inheritance
●
„Inheritance should only be used to
model a specialization hierarchy.“
●
“IS A ...“ vs. „HAS A ...“ means the
subclass “IS exactly the same AS …”
●
Inheritance hierarchies should be
shallow. (2-3)
●
See Liskov Substitution Principle (LSP).
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
Composition
over
Inheritance
Low Coupling
●
“Minimize the number of classes with which
another class collaborates.“
●
“Minimize the number of messages sent
between a class and its collaborator.“
●
Law of Demeter (“Only talk to friends”).
●
See Interface Segregation Principle (ISP).
●
e.g.
●
One Dot (dereference) Per Line. (OC#5)
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
High Cohesion
●
“Most of the methods defined on a class
should be using most of the data members
most of the time.“
●
Related data and behaviour in one place.
●
e.g.
●
Don’t Abbreviate (long names). (OC#6)
●
Keep All Entities Small. (OC#7)
●
Max Two Instance Variables. (OC#8)
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
Jeff Bay's Object Calisthenics
1. Only One Level Of Indentation Per Method.
2. Don’t Use The else Keyword.
3. Wrap All Primitives And Strings.
4. First Class Collections.
5. One Dot/Arrow (dereference) Per Line.
6. Don’t Abbreviate (long names).
7. Keep All Entities Small. (50 LoC per class)
8. Not More Than Two Instance Variables.
9. No Getters/Setters/Properties.
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
Try it yourself
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
Coding Dojo Mindset
●
Safe place outside
work
●
We are here to learn
●
Need to slow down
●
Focus on doing it right
●
Collaborative Game
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
Rules
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
Pair Programming & TDD
●
regular Pair Programming
●
do not talk for too long
●
do not interrupt the other
●
no “keyboard hugging“
●
use TDD (or at least “sort of” TDD)
●
write a test before you write code
●
refactor mercilessly
●
no debugger
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
LCD Numbers
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
Assignment
● Create an LCD string representation of an integer value using
a 4x7 grid of space, minus and pipe characters for each digit.
● Each digit is shown below (dot instead of space)
.--......--..--......--..--..--..--..--.
|..|...|...|...||..||...|......||..||..|
|..|...|...|...||..||...|......||..||..|
.........--..--..--..--..--......--..--.
|..|...||......|...|...||..|...||..|...|
|..|...||......|...|...||..|...||..|...|
.--......--..--......--..--......--..--.
● Bar size should be adjustable. The default value is 2.
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
“Calisthenics” Constraint
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
Jeff Bay's Object Calisthenics
1. Only One Level Of Indentation Per Method.
2. Don’t Use The else Keyword.
3. Wrap All Primitives And Strings.
4. First Class Collections.
5. One Dot/Arrow (dereference) Per Line.
6. Don’t Abbreviate (long names).
7. Keep All Entities Small. (50 LoC per class)
8. Not More Than Two Instance Variables.
9. No Getters/Setters/Properties.
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
Prepare
●
Find a pair.
●
Choose a programming language.
●
Get the Java project or create new one.
●
Implement LCD Numbers.
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
Don't Focus on
Getting it Done.
F0cus on Doing
It Perfectly.
→Practice
Closing Circle
●
What did you learn today?
●
What surprised you today?
●
What will you do
differently in the
future?
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
Peter Kofler
@codecopkofler
www.code-cop.org
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
CC Images
● Bruce http://www.flickr.com/photos/sherpas428/4350620602/
● pairing http://www.flickr.com/photos/dav/94735395/
● agenda http://www.flickr.com/photos/24293932@N00/2752221871/
● wants you http://www.flickr.com/photos/shutter/105497713/
● city http://www.flickr.com/photos/42311564@N00/2411037726/
● hands https://www.flickr.com/photos/ninahiironniemi/497993647/
● dojo http://www.flickr.com/photos/49715404@N00/3267627038/
● rule http://www.flickr.com/photos/phunk/4188827473
● LCD https://www.flickr.com/photos/ta3/3275907319/
● calisthenics https://www.flickr.com/photos/snickclunk/18522120656/
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY

Mais conteúdo relacionado

Mais procurados

JUnit Boot Camp (GeeCON 2016)
JUnit Boot Camp (GeeCON 2016)JUnit Boot Camp (GeeCON 2016)
JUnit Boot Camp (GeeCON 2016)Peter Kofler
 
Mob Programming (2016)
Mob Programming (2016)Mob Programming (2016)
Mob Programming (2016)Peter Kofler
 
Coding Dojo: Functional Calisthenics (2016)
Coding Dojo: Functional Calisthenics (2016)Coding Dojo: Functional Calisthenics (2016)
Coding Dojo: Functional Calisthenics (2016)Peter Kofler
 
Coding Dojo: Data Munging (2016)
Coding Dojo: Data Munging (2016)Coding Dojo: Data Munging (2016)
Coding Dojo: Data Munging (2016)Peter Kofler
 
Code Retreat Graz, Austria 2013
Code Retreat Graz, Austria 2013Code Retreat Graz, Austria 2013
Code Retreat Graz, Austria 2013Peter Kofler
 
Coding Dojo: Bank OCR Outside-In (2015)
Coding Dojo: Bank OCR Outside-In (2015)Coding Dojo: Bank OCR Outside-In (2015)
Coding Dojo: Bank OCR Outside-In (2015)Peter Kofler
 
Clean Readable Specifications (ETC 2016)
Clean Readable Specifications (ETC 2016)Clean Readable Specifications (ETC 2016)
Clean Readable Specifications (ETC 2016)Peter Kofler
 
TDD as if You Meant It (2013)
TDD as if You Meant It (2013)TDD as if You Meant It (2013)
TDD as if You Meant It (2013)Peter Kofler
 
Software Craftsmanship Journeyman Tour (2013)
Software Craftsmanship Journeyman Tour (2013)Software Craftsmanship Journeyman Tour (2013)
Software Craftsmanship Journeyman Tour (2013)Peter Kofler
 
Coding Dojo: Baby Steps Push Challenge (2021)
Coding Dojo: Baby Steps Push Challenge (2021)Coding Dojo: Baby Steps Push Challenge (2021)
Coding Dojo: Baby Steps Push Challenge (2021)Peter Kofler
 
Extract Method Refactoring Workshop (2016)
Extract Method Refactoring Workshop (2016)Extract Method Refactoring Workshop (2016)
Extract Method Refactoring Workshop (2016)Peter Kofler
 
Deliberate Practice, New Learning Styles (2015)
Deliberate Practice, New Learning Styles (2015)Deliberate Practice, New Learning Styles (2015)
Deliberate Practice, New Learning Styles (2015)Peter Kofler
 
Refactoring the Tennis Kata (2013)
Refactoring the Tennis Kata (2013)Refactoring the Tennis Kata (2013)
Refactoring the Tennis Kata (2013)Peter Kofler
 
Coding Dojo: Adding Tests to Legacy Code (2014)
Coding Dojo: Adding Tests to Legacy Code (2014)Coding Dojo: Adding Tests to Legacy Code (2014)
Coding Dojo: Adding Tests to Legacy Code (2014)Peter Kofler
 
Idiomatic R for Rosetta Code (2013)
Idiomatic R for Rosetta Code (2013)Idiomatic R for Rosetta Code (2013)
Idiomatic R for Rosetta Code (2013)Peter Kofler
 
Using Automated Code Reviews to Achieve Continuous Quality (ASQF Agile Night ...
Using Automated Code Reviews to Achieve Continuous Quality (ASQF Agile Night ...Using Automated Code Reviews to Achieve Continuous Quality (ASQF Agile Night ...
Using Automated Code Reviews to Achieve Continuous Quality (ASQF Agile Night ...Peter Kofler
 
Outside-in Test Driven Development - the London School of TDD
Outside-in Test Driven Development - the London School of TDDOutside-in Test Driven Development - the London School of TDD
Outside-in Test Driven Development - the London School of TDDPeter Kofler
 
Code Quality Assurance v4 (2013)
Code Quality Assurance v4 (2013)Code Quality Assurance v4 (2013)
Code Quality Assurance v4 (2013)Peter Kofler
 
Coding Dojo: Naming with Dices (2021)
Coding Dojo: Naming with Dices (2021)Coding Dojo: Naming with Dices (2021)
Coding Dojo: Naming with Dices (2021)Peter Kofler
 
Coding Dojo: Mars Rover (2014)
Coding Dojo: Mars Rover (2014)Coding Dojo: Mars Rover (2014)
Coding Dojo: Mars Rover (2014)Peter Kofler
 

Mais procurados (20)

JUnit Boot Camp (GeeCON 2016)
JUnit Boot Camp (GeeCON 2016)JUnit Boot Camp (GeeCON 2016)
JUnit Boot Camp (GeeCON 2016)
 
Mob Programming (2016)
Mob Programming (2016)Mob Programming (2016)
Mob Programming (2016)
 
Coding Dojo: Functional Calisthenics (2016)
Coding Dojo: Functional Calisthenics (2016)Coding Dojo: Functional Calisthenics (2016)
Coding Dojo: Functional Calisthenics (2016)
 
Coding Dojo: Data Munging (2016)
Coding Dojo: Data Munging (2016)Coding Dojo: Data Munging (2016)
Coding Dojo: Data Munging (2016)
 
Code Retreat Graz, Austria 2013
Code Retreat Graz, Austria 2013Code Retreat Graz, Austria 2013
Code Retreat Graz, Austria 2013
 
Coding Dojo: Bank OCR Outside-In (2015)
Coding Dojo: Bank OCR Outside-In (2015)Coding Dojo: Bank OCR Outside-In (2015)
Coding Dojo: Bank OCR Outside-In (2015)
 
Clean Readable Specifications (ETC 2016)
Clean Readable Specifications (ETC 2016)Clean Readable Specifications (ETC 2016)
Clean Readable Specifications (ETC 2016)
 
TDD as if You Meant It (2013)
TDD as if You Meant It (2013)TDD as if You Meant It (2013)
TDD as if You Meant It (2013)
 
Software Craftsmanship Journeyman Tour (2013)
Software Craftsmanship Journeyman Tour (2013)Software Craftsmanship Journeyman Tour (2013)
Software Craftsmanship Journeyman Tour (2013)
 
Coding Dojo: Baby Steps Push Challenge (2021)
Coding Dojo: Baby Steps Push Challenge (2021)Coding Dojo: Baby Steps Push Challenge (2021)
Coding Dojo: Baby Steps Push Challenge (2021)
 
Extract Method Refactoring Workshop (2016)
Extract Method Refactoring Workshop (2016)Extract Method Refactoring Workshop (2016)
Extract Method Refactoring Workshop (2016)
 
Deliberate Practice, New Learning Styles (2015)
Deliberate Practice, New Learning Styles (2015)Deliberate Practice, New Learning Styles (2015)
Deliberate Practice, New Learning Styles (2015)
 
Refactoring the Tennis Kata (2013)
Refactoring the Tennis Kata (2013)Refactoring the Tennis Kata (2013)
Refactoring the Tennis Kata (2013)
 
Coding Dojo: Adding Tests to Legacy Code (2014)
Coding Dojo: Adding Tests to Legacy Code (2014)Coding Dojo: Adding Tests to Legacy Code (2014)
Coding Dojo: Adding Tests to Legacy Code (2014)
 
Idiomatic R for Rosetta Code (2013)
Idiomatic R for Rosetta Code (2013)Idiomatic R for Rosetta Code (2013)
Idiomatic R for Rosetta Code (2013)
 
Using Automated Code Reviews to Achieve Continuous Quality (ASQF Agile Night ...
Using Automated Code Reviews to Achieve Continuous Quality (ASQF Agile Night ...Using Automated Code Reviews to Achieve Continuous Quality (ASQF Agile Night ...
Using Automated Code Reviews to Achieve Continuous Quality (ASQF Agile Night ...
 
Outside-in Test Driven Development - the London School of TDD
Outside-in Test Driven Development - the London School of TDDOutside-in Test Driven Development - the London School of TDD
Outside-in Test Driven Development - the London School of TDD
 
Code Quality Assurance v4 (2013)
Code Quality Assurance v4 (2013)Code Quality Assurance v4 (2013)
Code Quality Assurance v4 (2013)
 
Coding Dojo: Naming with Dices (2021)
Coding Dojo: Naming with Dices (2021)Coding Dojo: Naming with Dices (2021)
Coding Dojo: Naming with Dices (2021)
 
Coding Dojo: Mars Rover (2014)
Coding Dojo: Mars Rover (2014)Coding Dojo: Mars Rover (2014)
Coding Dojo: Mars Rover (2014)
 

Semelhante a Object Calisthenics Coding Exercise

Global Day of Code Retreat (2013)
Global Day of Code Retreat (2013)Global Day of Code Retreat (2013)
Global Day of Code Retreat (2013)Peter Kofler
 
Coding Dojo: Bank OCR (2014)
Coding Dojo: Bank OCR (2014)Coding Dojo: Bank OCR (2014)
Coding Dojo: Bank OCR (2014)Peter Kofler
 
Coding Dojo: String Calculator (2013)
Coding Dojo: String Calculator (2013)Coding Dojo: String Calculator (2013)
Coding Dojo: String Calculator (2013)Peter Kofler
 
Prime Factors Code Kata - Practicing TDD (2014)
Prime Factors Code Kata - Practicing TDD (2014)Prime Factors Code Kata - Practicing TDD (2014)
Prime Factors Code Kata - Practicing TDD (2014)Peter Kofler
 
Can PL/SQL be Clean? (2013)
Can PL/SQL be Clean? (2013)Can PL/SQL be Clean? (2013)
Can PL/SQL be Clean? (2013)Peter Kofler
 
Coding Dojo: Roman Numerals (2014)
Coding Dojo: Roman Numerals (2014)Coding Dojo: Roman Numerals (2014)
Coding Dojo: Roman Numerals (2014)Peter Kofler
 
Pragmatic Introduction to Python Unit Testing (PyDays 2018)
Pragmatic Introduction to Python Unit Testing (PyDays 2018)Pragmatic Introduction to Python Unit Testing (PyDays 2018)
Pragmatic Introduction to Python Unit Testing (PyDays 2018)Peter Kofler
 
Deliberate Practice (2014)
Deliberate Practice (2014)Deliberate Practice (2014)
Deliberate Practice (2014)Peter Kofler
 
Coding Dojo: Fun with Tic-Tac-Toe (2014)
Coding Dojo: Fun with Tic-Tac-Toe (2014)Coding Dojo: Fun with Tic-Tac-Toe (2014)
Coding Dojo: Fun with Tic-Tac-Toe (2014)Peter Kofler
 
Pair Programming (2014)
Pair Programming (2014)Pair Programming (2014)
Pair Programming (2014)Peter Kofler
 
GDCR15 in Las Palmas, Gran Canaria
GDCR15 in Las Palmas, Gran CanariaGDCR15 in Las Palmas, Gran Canaria
GDCR15 in Las Palmas, Gran CanariaPeter Kofler
 
Coding Dojo: Tic-Tac-Toe (2014)
Coding Dojo: Tic-Tac-Toe (2014)Coding Dojo: Tic-Tac-Toe (2014)
Coding Dojo: Tic-Tac-Toe (2014)Peter Kofler
 
Pair Programming (2015)
Pair Programming (2015)Pair Programming (2015)
Pair Programming (2015)Peter Kofler
 
Software Craftmanship - Cours Polytech
Software Craftmanship - Cours PolytechSoftware Craftmanship - Cours Polytech
Software Craftmanship - Cours Polytechyannick grenzinger
 
Coding Dojo: Baby Steps (2014)
Coding Dojo: Baby Steps (2014)Coding Dojo: Baby Steps (2014)
Coding Dojo: Baby Steps (2014)Peter Kofler
 
Clean Code Part III - Craftsmanship at SoCal Code Camp
Clean Code Part III - Craftsmanship at SoCal Code CampClean Code Part III - Craftsmanship at SoCal Code Camp
Clean Code Part III - Craftsmanship at SoCal Code CampTheo Jungeblut
 

Semelhante a Object Calisthenics Coding Exercise (16)

Global Day of Code Retreat (2013)
Global Day of Code Retreat (2013)Global Day of Code Retreat (2013)
Global Day of Code Retreat (2013)
 
Coding Dojo: Bank OCR (2014)
Coding Dojo: Bank OCR (2014)Coding Dojo: Bank OCR (2014)
Coding Dojo: Bank OCR (2014)
 
Coding Dojo: String Calculator (2013)
Coding Dojo: String Calculator (2013)Coding Dojo: String Calculator (2013)
Coding Dojo: String Calculator (2013)
 
Prime Factors Code Kata - Practicing TDD (2014)
Prime Factors Code Kata - Practicing TDD (2014)Prime Factors Code Kata - Practicing TDD (2014)
Prime Factors Code Kata - Practicing TDD (2014)
 
Can PL/SQL be Clean? (2013)
Can PL/SQL be Clean? (2013)Can PL/SQL be Clean? (2013)
Can PL/SQL be Clean? (2013)
 
Coding Dojo: Roman Numerals (2014)
Coding Dojo: Roman Numerals (2014)Coding Dojo: Roman Numerals (2014)
Coding Dojo: Roman Numerals (2014)
 
Pragmatic Introduction to Python Unit Testing (PyDays 2018)
Pragmatic Introduction to Python Unit Testing (PyDays 2018)Pragmatic Introduction to Python Unit Testing (PyDays 2018)
Pragmatic Introduction to Python Unit Testing (PyDays 2018)
 
Deliberate Practice (2014)
Deliberate Practice (2014)Deliberate Practice (2014)
Deliberate Practice (2014)
 
Coding Dojo: Fun with Tic-Tac-Toe (2014)
Coding Dojo: Fun with Tic-Tac-Toe (2014)Coding Dojo: Fun with Tic-Tac-Toe (2014)
Coding Dojo: Fun with Tic-Tac-Toe (2014)
 
Pair Programming (2014)
Pair Programming (2014)Pair Programming (2014)
Pair Programming (2014)
 
GDCR15 in Las Palmas, Gran Canaria
GDCR15 in Las Palmas, Gran CanariaGDCR15 in Las Palmas, Gran Canaria
GDCR15 in Las Palmas, Gran Canaria
 
Coding Dojo: Tic-Tac-Toe (2014)
Coding Dojo: Tic-Tac-Toe (2014)Coding Dojo: Tic-Tac-Toe (2014)
Coding Dojo: Tic-Tac-Toe (2014)
 
Pair Programming (2015)
Pair Programming (2015)Pair Programming (2015)
Pair Programming (2015)
 
Software Craftmanship - Cours Polytech
Software Craftmanship - Cours PolytechSoftware Craftmanship - Cours Polytech
Software Craftmanship - Cours Polytech
 
Coding Dojo: Baby Steps (2014)
Coding Dojo: Baby Steps (2014)Coding Dojo: Baby Steps (2014)
Coding Dojo: Baby Steps (2014)
 
Clean Code Part III - Craftsmanship at SoCal Code Camp
Clean Code Part III - Craftsmanship at SoCal Code CampClean Code Part III - Craftsmanship at SoCal Code Camp
Clean Code Part III - Craftsmanship at SoCal Code Camp
 

Último

Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 

Último (20)

Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 

Object Calisthenics Coding Exercise

  • 1. Object Calisthenics October 2016 Peter Kofler, ‘Code Cop’ @codecopkofler www.code-cop.org Copyright Peter Kofler, licensed under CC-BY.
  • 2. Peter Kofler • Ph.D. (Appl. Math.) • Professional Software Developer for 15+ years • “fanatic about code quality” • Freelance Code Mentor PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
  • 3. I help development teams with PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY ● Professionalism ● Quality and Productivity ● Continuous Improvement
  • 4. Mentoring PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY ● Pair Programming ● Programming Workshops ● Deliberate Practice, e.g. Coding Dojos
  • 6. Agenda ● Concepts of OO ● Encapsulation ● Coupling and Cohesion ● Coding Exercise “Object Calisthenics” PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
  • 7. Discussion ● What is Object Orientation? ● What are its basic features? PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
  • 8. OOP is based on ● Abstraction ● Encapsulation ● Polymorphy ● Inheritance ● Coupling ● Cohesion PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
  • 9. Abstraction ● “A class should capture one and only one key abstraction.” ● Avoid Primitive Obsession. ● Single Responsibility Principle (SRP). ● Wrap All Primitives And Strings. (OC#3) ● First Class Collections. (OC#4) ● Keep All Entities Small. (OC#7) PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
  • 10. Encapsulation ● “Objects are defined by what they do, not what they contain.“ ● All data should be hidden within its class. ● Tell, Don't Ask. ● e.g. ● All fields must be private. ● No Getters/Setters/Properties. (OC#9) PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
  • 11. Polymorphy ● Avoid switch statements (Type Code). ● “Explicit case on the type of an object (instanceof) is usually an error.” ● Open Closed Principle (OCP). ● e.g. ● Avoid switch statements. ● Don’t Use The else Keyword. (OC#2) PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
  • 12. Inheritance ● „Inheritance should only be used to model a specialization hierarchy.“ ● “IS A ...“ vs. „HAS A ...“ means the subclass “IS exactly the same AS …” ● Inheritance hierarchies should be shallow. (2-3) ● See Liskov Substitution Principle (LSP). PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
  • 14. Low Coupling ● “Minimize the number of classes with which another class collaborates.“ ● “Minimize the number of messages sent between a class and its collaborator.“ ● Law of Demeter (“Only talk to friends”). ● See Interface Segregation Principle (ISP). ● e.g. ● One Dot (dereference) Per Line. (OC#5) PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
  • 15. High Cohesion ● “Most of the methods defined on a class should be using most of the data members most of the time.“ ● Related data and behaviour in one place. ● e.g. ● Don’t Abbreviate (long names). (OC#6) ● Keep All Entities Small. (OC#7) ● Max Two Instance Variables. (OC#8) PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
  • 16. Jeff Bay's Object Calisthenics 1. Only One Level Of Indentation Per Method. 2. Don’t Use The else Keyword. 3. Wrap All Primitives And Strings. 4. First Class Collections. 5. One Dot/Arrow (dereference) Per Line. 6. Don’t Abbreviate (long names). 7. Keep All Entities Small. (50 LoC per class) 8. Not More Than Two Instance Variables. 9. No Getters/Setters/Properties. PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
  • 17. Try it yourself PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
  • 18. Coding Dojo Mindset ● Safe place outside work ● We are here to learn ● Need to slow down ● Focus on doing it right ● Collaborative Game PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
  • 19. Rules PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
  • 20. Pair Programming & TDD ● regular Pair Programming ● do not talk for too long ● do not interrupt the other ● no “keyboard hugging“ ● use TDD (or at least “sort of” TDD) ● write a test before you write code ● refactor mercilessly ● no debugger PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
  • 21. LCD Numbers PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
  • 22. Assignment ● Create an LCD string representation of an integer value using a 4x7 grid of space, minus and pipe characters for each digit. ● Each digit is shown below (dot instead of space) .--......--..--......--..--..--..--..--. |..|...|...|...||..||...|......||..||..| |..|...|...|...||..||...|......||..||..| .........--..--..--..--..--......--..--. |..|...||......|...|...||..|...||..|...| |..|...||......|...|...||..|...||..|...| .--......--..--......--..--......--..--. ● Bar size should be adjustable. The default value is 2. PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
  • 23. “Calisthenics” Constraint PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
  • 24. Jeff Bay's Object Calisthenics 1. Only One Level Of Indentation Per Method. 2. Don’t Use The else Keyword. 3. Wrap All Primitives And Strings. 4. First Class Collections. 5. One Dot/Arrow (dereference) Per Line. 6. Don’t Abbreviate (long names). 7. Keep All Entities Small. (50 LoC per class) 8. Not More Than Two Instance Variables. 9. No Getters/Setters/Properties. PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
  • 25. Prepare ● Find a pair. ● Choose a programming language. ● Get the Java project or create new one. ● Implement LCD Numbers. PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
  • 26. Don't Focus on Getting it Done. F0cus on Doing It Perfectly.
  • 28. Closing Circle ● What did you learn today? ● What surprised you today? ● What will you do differently in the future? PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
  • 29. Peter Kofler @codecopkofler www.code-cop.org PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
  • 30. CC Images ● Bruce http://www.flickr.com/photos/sherpas428/4350620602/ ● pairing http://www.flickr.com/photos/dav/94735395/ ● agenda http://www.flickr.com/photos/24293932@N00/2752221871/ ● wants you http://www.flickr.com/photos/shutter/105497713/ ● city http://www.flickr.com/photos/42311564@N00/2411037726/ ● hands https://www.flickr.com/photos/ninahiironniemi/497993647/ ● dojo http://www.flickr.com/photos/49715404@N00/3267627038/ ● rule http://www.flickr.com/photos/phunk/4188827473 ● LCD https://www.flickr.com/photos/ta3/3275907319/ ● calisthenics https://www.flickr.com/photos/snickclunk/18522120656/ PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY