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
DeveloperHerder
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)
REWRITEALL 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 codemake it easier to comprehend
Improve codemake it easier to comprehend
make it flexible
Improve codemake it easier to comprehend
make it flexible
make it tested
Improve codemake it easier to comprehend
make it flexible
make it tested
make it easier to replace, refactor
Improve codemake 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 ResponsibilityOpen and Close
Liskov substitutionInterface SegregationDependency Inversion
STUPIDSingleton
Tight CouplingUntestability
Premature OptimizationIndescriptive Naming
Duplication
Design Patterns
photo by halloweenstock
Package Managers
Composer
PIEProudly
InventedElsewhere
guzzlehttp/guzzleHTTP client for RESTful API clients
league/tacticianA flexible CommandBus implementation
Readability
photo: Morgenland
paragraphs
photo: Trossachs Photography
whitespace
R&D Team for MIH/Naspers
São PauloCape 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
https://joind.in/talk/6236e
http://l.doh.ms/oc-material
Video recording
Slides
Books
Resources on Object Calisthenics