SlideShare una empresa de Scribd logo
1 de 74
Descargar para leer sin conexión
Writing code
that lasts.
Rafael Dohms

@rdohms
photo: djandyw.com
#ocforphp
Writing code 

you won’t hate tomorrow.
Rafael Dohms

@rdohms
photo: djandyw.com
#ocforphp
Rafael Dohms
or @rdohms on twitter
Developer
Herder
at AmsterdamPHP
Lead Backend
Developer
at Symbid
Let me
tell you about
someone else…
No Tests.
Wrote his own framework.
500 line methods.
Used Singletons!
shhh.. don’t tell Grumpy.
.. and used it.
.. and every other anti-pattern out there.
… not even methods, they were functions
photo: Rob Allen (@akrabat)
REWRITE
ALL THE CODE!
image: hyperboleandahalf
Real Developers,
SHIP STUFF.
photo: Glyn Lowe Photoworks
How do we find
balance?
photo: Kalexanderson
Code has an
expiration date
photo: CarbonNYC
Code is
perishable, it rots.
photo by: massdistraction
Code Evolves
photo by: kevin dooley
Languages evolve.
photo by: raneko
You evolve.
photo by: Kaptain Kobold
Complexity 

kills
Comprehension
photo: osbornb
Bad Design
photo: miskan
Bad specs
NIH
source: Urban dictionary
photo by: John 'K'
NIH
| nɒt ɪnˈventɪd hɪə |

Not Invented Here —The German art of humiliating any technology,
agricultural product, or (medical) scientific work that has not been
invented or produced in Germany, Switzerland, or Austria.
source: Urban dictionary
photo by: John 'K'
The Solution™
photo: Ian Sane
Improve code
Improve code
make it easier to comprehend
Improve code
make it easier to comprehend
make it flexible
Improve code
make it easier to comprehend
make it flexible
make it tested
Improve code
make it easier to comprehend
make it flexible
make it tested
make it easier to replace, refactor
Improve code
make it easier to comprehend
make it flexible
make it tested
make it easier to replace, refactor
make it not exist
Testing
photo by: jeffkrause
Good Design
Concepts
SOLID
Single Responsibility

Open and Close

Liskov substitution

Interface Segregation

Dependency Inversion
photo by j_regan
photo by lofink
STUPID
Singleton

Tight Coupling

Untestability

Premature Optimization

Indescriptive Naming

Duplication
Design Patterns
photo by halloweenstock
Package
Managers
photo by cocoachuchu.etsy.com
PIE
Proudly

Invented

Elsewhere
Readability
photo: Morgenland
paragraphs
photo: Trossachs Photography
whitespace
R&D Team for MIH/Naspers
São Paulo
Cape Town
Object
Calisthenics
photo by: boston_public_library
Calisthenics
/ˌkaləsˈTHeniks/
Calisthenics are a form of dynamic exercise consisting of a variety of
simple, often rhythmical, movements, generally using minimal
equipment or apparatus.
photo by: boston_public_library
Its about perception,
not rules or standards photo by: david_a_l
#1
Only one
indentation level
per method.
photo by: justinliew
#2
Do not 

use else
photo by: justinliew
#3
Wrap primitive
types, if they
contain behavior
photo by: justinliew
$component->repaint(false);
$component->repaint( new Animate(false) );
#4
Only one 

-> per line
photo by: justinliew
#5
Do not
abbreviate.
photo by: justinliew
if($sx >= $sy) {
if ($sx > $strSysMatImgW) {
$ny = $strSysMatImgW * $sy / $sx;
$nx = $strSysMatImgW;
}
if ($ny > $strSysMatImgH) {
$nx = $strSysMatImgH * $sx / $sy;
$ny = $strSysMatImgH;
}
}
#6
Keep your
classes small.
photo by: justinliew
#7
Limit your
instance variables
to less then 5
photo by: justinliew
#8
Use first class
collections
photo by: justinliew
#9
Don’t use getters
and setters.
photo by: justinliew
#10
Document
your code.
photo by: justinliew
Your turn.
Improve
yourself!
Read lots of
code!
Write simple
code.
Try Object Calisthenics
for a month.
Use someone
else’s code.
Share bite size
libraries.
Thank you.
http://slides.doh.ms
http://doh.ms
@rdohms
we are hiring!
http://careers.symbid.com
http://l.doh.ms/oc-material
Video recording
Slides
Books
Resources on 

Object Calisthenics

Más contenido relacionado

La actualidad más candente

MSR2014 - An Empirical Study of Dormant Bugs
MSR2014 - An Empirical Study of Dormant BugsMSR2014 - An Empirical Study of Dormant Bugs
MSR2014 - An Empirical Study of Dormant Bugs
Concordia University
 

La actualidad más candente (6)

Writing Code That Lasts - #Magento2Seminar, Utrecht
Writing Code That Lasts - #Magento2Seminar, UtrechtWriting Code That Lasts - #Magento2Seminar, Utrecht
Writing Code That Lasts - #Magento2Seminar, Utrecht
 
Failure as Success Devops Roadtrip Seattle 2016
Failure as Success Devops Roadtrip Seattle 2016Failure as Success Devops Roadtrip Seattle 2016
Failure as Success Devops Roadtrip Seattle 2016
 
Continuous Integration: Blueprint, Toolbox, Master Craft
Continuous Integration: Blueprint, Toolbox, Master CraftContinuous Integration: Blueprint, Toolbox, Master Craft
Continuous Integration: Blueprint, Toolbox, Master Craft
 
DEV.BG - Angular 1 and Jasmine (Unit Testing and TDD)
DEV.BG - Angular 1 and Jasmine (Unit Testing and TDD)DEV.BG - Angular 1 and Jasmine (Unit Testing and TDD)
DEV.BG - Angular 1 and Jasmine (Unit Testing and TDD)
 
MSR2014 - An Empirical Study of Dormant Bugs
MSR2014 - An Empirical Study of Dormant BugsMSR2014 - An Empirical Study of Dormant Bugs
MSR2014 - An Empirical Study of Dormant Bugs
 
How to use github to evaluate developers
How to use github to evaluate developersHow to use github to evaluate developers
How to use github to evaluate developers
 

Más de Rafael Dohms

Más de Rafael Dohms (20)

The Individual Contributor Path - DPC2024
The Individual Contributor Path - DPC2024The Individual Contributor Path - DPC2024
The Individual Contributor Path - DPC2024
 
Application Metrics - IPC2023
Application Metrics - IPC2023Application Metrics - IPC2023
Application Metrics - IPC2023
 
How'd we get here? A guide to Architectural Decision Records
How'd we get here? A guide to Architectural Decision RecordsHow'd we get here? A guide to Architectural Decision Records
How'd we get here? A guide to Architectural Decision Records
 
Architectural Decision Records - PHPConfBR
Architectural Decision Records - PHPConfBRArchitectural Decision Records - PHPConfBR
Architectural Decision Records - PHPConfBR
 
Application Metrics (with Prometheus examples)
Application Metrics (with Prometheus examples)Application Metrics (with Prometheus examples)
Application Metrics (with Prometheus examples)
 
Application metrics - Confoo 2019
Application metrics - Confoo 2019Application metrics - Confoo 2019
Application metrics - Confoo 2019
 
Writing code you won’t hate tomorrow - PHPCE18
Writing code you won’t hate tomorrow - PHPCE18Writing code you won’t hate tomorrow - PHPCE18
Writing code you won’t hate tomorrow - PHPCE18
 
Application Metrics (with Prometheus examples) #PHPDD18
Application Metrics (with Prometheus examples) #PHPDD18Application Metrics (with Prometheus examples) #PHPDD18
Application Metrics (with Prometheus examples) #PHPDD18
 
Application metrics with Prometheus - DPC18
Application metrics with Prometheus - DPC18Application metrics with Prometheus - DPC18
Application metrics with Prometheus - DPC18
 
“Writing code that lasts” … or writing code you won’t hate tomorrow. - PHPKonf
“Writing code that lasts” … or writing code you won’t hate tomorrow. - PHPKonf“Writing code that lasts” … or writing code you won’t hate tomorrow. - PHPKonf
“Writing code that lasts” … or writing code you won’t hate tomorrow. - PHPKonf
 
“Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yo...
“Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yo...“Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yo...
“Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yo...
 
Composer The Right Way - 010PHP
Composer The Right Way - 010PHPComposer The Right Way - 010PHP
Composer The Right Way - 010PHP
 
Composer the Right Way - PHPSRB16
Composer the Right Way - PHPSRB16Composer the Right Way - PHPSRB16
Composer the Right Way - PHPSRB16
 
Composer the Right Way - MM16NL
Composer the Right Way - MM16NLComposer the Right Way - MM16NL
Composer the Right Way - MM16NL
 
Composer The Right Way - PHPUGMRN
Composer The Right Way - PHPUGMRNComposer The Right Way - PHPUGMRN
Composer The Right Way - PHPUGMRN
 
Composer the Right Way - PHPBNL16
Composer the Right Way - PHPBNL16Composer the Right Way - PHPBNL16
Composer the Right Way - PHPBNL16
 
A Journey into your Lizard Brain - PHP Conference Brasil 2015
A Journey into your Lizard Brain - PHP Conference Brasil 2015A Journey into your Lizard Brain - PHP Conference Brasil 2015
A Journey into your Lizard Brain - PHP Conference Brasil 2015
 
Journey into your Lizard Brain - PHPJHB15
Journey into your Lizard Brain - PHPJHB15Journey into your Lizard Brain - PHPJHB15
Journey into your Lizard Brain - PHPJHB15
 
Composer The Right Way #PHPjhb15
Composer The Right Way #PHPjhb15Composer The Right Way #PHPjhb15
Composer The Right Way #PHPjhb15
 
Composer the right way - DPC15
Composer the right way - DPC15Composer the right way - DPC15
Composer the right way - DPC15
 

Último

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Último (20)

Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 

“Writing code that lasts” … or writing code you won’t hate tomorrow.