![Page 1: “Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yorkshire](https://reader031.vdocuments.site/reader031/viewer/2022022413/58eeee4b1a28abe65b8b45f3/html5/thumbnails/1.jpg)
Writing code that lasts.
Rafael Dohms@rdohms
photo: djandyw.com
![Page 2: “Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yorkshire](https://reader031.vdocuments.site/reader031/viewer/2022022413/58eeee4b1a28abe65b8b45f3/html5/thumbnails/2.jpg)
Writing code you won’t hate tomorrow.
Rafael Dohms@rdohms
photo: djandyw.com
![Page 3: “Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yorkshire](https://reader031.vdocuments.site/reader031/viewer/2022022413/58eeee4b1a28abe65b8b45f3/html5/thumbnails/3.jpg)
Lead Backend EngineerRafael Dohms
jobs.usabilla.com
@rdohms on twitter
![Page 4: “Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yorkshire](https://reader031.vdocuments.site/reader031/viewer/2022022413/58eeee4b1a28abe65b8b45f3/html5/thumbnails/4.jpg)
Lead Backend EngineerRafael Dohms
jobs.usabilla.com
Feedback
Feedback
@rdohms on twitter
![Page 5: “Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yorkshire](https://reader031.vdocuments.site/reader031/viewer/2022022413/58eeee4b1a28abe65b8b45f3/html5/thumbnails/5.jpg)
![Page 6: “Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yorkshire](https://reader031.vdocuments.site/reader031/viewer/2022022413/58eeee4b1a28abe65b8b45f3/html5/thumbnails/6.jpg)
photo: Rob Allen (@akrabat)
![Page 7: “Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yorkshire](https://reader031.vdocuments.site/reader031/viewer/2022022413/58eeee4b1a28abe65b8b45f3/html5/thumbnails/7.jpg)
![Page 8: “Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yorkshire](https://reader031.vdocuments.site/reader031/viewer/2022022413/58eeee4b1a28abe65b8b45f3/html5/thumbnails/8.jpg)
REWRITEALL THE CODE!
image: hyperboleandahalf
![Page 9: “Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yorkshire](https://reader031.vdocuments.site/reader031/viewer/2022022413/58eeee4b1a28abe65b8b45f3/html5/thumbnails/9.jpg)
Real Developers, SHIP STUFF.
photo: Glyn Lowe Photoworks
![Page 10: “Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yorkshire](https://reader031.vdocuments.site/reader031/viewer/2022022413/58eeee4b1a28abe65b8b45f3/html5/thumbnails/10.jpg)
![Page 11: “Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yorkshire](https://reader031.vdocuments.site/reader031/viewer/2022022413/58eeee4b1a28abe65b8b45f3/html5/thumbnails/11.jpg)
![Page 12: “Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yorkshire](https://reader031.vdocuments.site/reader031/viewer/2022022413/58eeee4b1a28abe65b8b45f3/html5/thumbnails/12.jpg)
![Page 13: “Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yorkshire](https://reader031.vdocuments.site/reader031/viewer/2022022413/58eeee4b1a28abe65b8b45f3/html5/thumbnails/13.jpg)
How do we find balance?
photo: Kalexanderson
![Page 14: “Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yorkshire](https://reader031.vdocuments.site/reader031/viewer/2022022413/58eeee4b1a28abe65b8b45f3/html5/thumbnails/14.jpg)
Code has an expiration date
photo: CarbonNYC
![Page 15: “Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yorkshire](https://reader031.vdocuments.site/reader031/viewer/2022022413/58eeee4b1a28abe65b8b45f3/html5/thumbnails/15.jpg)
Code is perishable, it rots.
photo by: massdistraction
![Page 16: “Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yorkshire](https://reader031.vdocuments.site/reader031/viewer/2022022413/58eeee4b1a28abe65b8b45f3/html5/thumbnails/16.jpg)
Code Evolves
photo by: kevin dooley
![Page 17: “Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yorkshire](https://reader031.vdocuments.site/reader031/viewer/2022022413/58eeee4b1a28abe65b8b45f3/html5/thumbnails/17.jpg)
Languages evolve.photo by: raneko
![Page 18: “Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yorkshire](https://reader031.vdocuments.site/reader031/viewer/2022022413/58eeee4b1a28abe65b8b45f3/html5/thumbnails/18.jpg)
You evolve.
photo by: Kaptain Kobold
![Page 19: “Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yorkshire](https://reader031.vdocuments.site/reader031/viewer/2022022413/58eeee4b1a28abe65b8b45f3/html5/thumbnails/19.jpg)
Complexity kills Comprehension
photo: osbornb
![Page 20: “Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yorkshire](https://reader031.vdocuments.site/reader031/viewer/2022022413/58eeee4b1a28abe65b8b45f3/html5/thumbnails/20.jpg)
Bad Design
photo: miskan
![Page 21: “Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yorkshire](https://reader031.vdocuments.site/reader031/viewer/2022022413/58eeee4b1a28abe65b8b45f3/html5/thumbnails/21.jpg)
Bad specs
![Page 22: “Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yorkshire](https://reader031.vdocuments.site/reader031/viewer/2022022413/58eeee4b1a28abe65b8b45f3/html5/thumbnails/22.jpg)
NIH
source: Urban dictionary
photo by: John 'K'
![Page 23: “Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yorkshire](https://reader031.vdocuments.site/reader031/viewer/2022022413/58eeee4b1a28abe65b8b45f3/html5/thumbnails/23.jpg)
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'
![Page 24: “Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yorkshire](https://reader031.vdocuments.site/reader031/viewer/2022022413/58eeee4b1a28abe65b8b45f3/html5/thumbnails/24.jpg)
The Solution™photo: Ian Sane
![Page 25: “Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yorkshire](https://reader031.vdocuments.site/reader031/viewer/2022022413/58eeee4b1a28abe65b8b45f3/html5/thumbnails/25.jpg)
Improve code
![Page 26: “Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yorkshire](https://reader031.vdocuments.site/reader031/viewer/2022022413/58eeee4b1a28abe65b8b45f3/html5/thumbnails/26.jpg)
Improve codemake it easier to comprehend
![Page 27: “Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yorkshire](https://reader031.vdocuments.site/reader031/viewer/2022022413/58eeee4b1a28abe65b8b45f3/html5/thumbnails/27.jpg)
Improve codemake it easier to comprehend
make it flexible
![Page 28: “Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yorkshire](https://reader031.vdocuments.site/reader031/viewer/2022022413/58eeee4b1a28abe65b8b45f3/html5/thumbnails/28.jpg)
Improve codemake it easier to comprehend
make it flexible
make it tested
![Page 29: “Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yorkshire](https://reader031.vdocuments.site/reader031/viewer/2022022413/58eeee4b1a28abe65b8b45f3/html5/thumbnails/29.jpg)
Improve codemake it easier to comprehend
make it flexible
make it tested
make it easier to replace, refactor
![Page 30: “Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yorkshire](https://reader031.vdocuments.site/reader031/viewer/2022022413/58eeee4b1a28abe65b8b45f3/html5/thumbnails/30.jpg)
Improve codemake it easier to comprehend
make it flexible
make it tested
make it easier to replace, refactor
make it not exist
![Page 31: “Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yorkshire](https://reader031.vdocuments.site/reader031/viewer/2022022413/58eeee4b1a28abe65b8b45f3/html5/thumbnails/31.jpg)
Testing
photo by: jeffkrause
![Page 32: “Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yorkshire](https://reader031.vdocuments.site/reader031/viewer/2022022413/58eeee4b1a28abe65b8b45f3/html5/thumbnails/32.jpg)
"Refactoring without tests is just changing stuff."
![Page 33: “Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yorkshire](https://reader031.vdocuments.site/reader031/viewer/2022022413/58eeee4b1a28abe65b8b45f3/html5/thumbnails/33.jpg)
Good Design Concepts
![Page 34: “Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yorkshire](https://reader031.vdocuments.site/reader031/viewer/2022022413/58eeee4b1a28abe65b8b45f3/html5/thumbnails/34.jpg)
Single Responsibility Open and Close
Liskov substitution Interface Segregation Dependency Inversion
SingletonTight CouplingUntestability
Premature Optimization Indescriptive Naming
Duplication
Solid Stupid
○"
![Page 35: “Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yorkshire](https://reader031.vdocuments.site/reader031/viewer/2022022413/58eeee4b1a28abe65b8b45f3/html5/thumbnails/35.jpg)
Design Patterns
photo by halloweenstock
![Page 36: “Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yorkshire](https://reader031.vdocuments.site/reader031/viewer/2022022413/58eeee4b1a28abe65b8b45f3/html5/thumbnails/36.jpg)
Domain Driven Designwith Ubiquitous Language
photo by lwr
![Page 37: “Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yorkshire](https://reader031.vdocuments.site/reader031/viewer/2022022413/58eeee4b1a28abe65b8b45f3/html5/thumbnails/37.jpg)
Modular ArchitectureCQRS, Event Sourcing, Micro Services
photo by medialoog
![Page 38: “Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yorkshire](https://reader031.vdocuments.site/reader031/viewer/2022022413/58eeee4b1a28abe65b8b45f3/html5/thumbnails/38.jpg)
Package Managers
![Page 39: “Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yorkshire](https://reader031.vdocuments.site/reader031/viewer/2022022413/58eeee4b1a28abe65b8b45f3/html5/thumbnails/39.jpg)
PIEProudly
InventedElsewhere
![Page 40: “Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yorkshire](https://reader031.vdocuments.site/reader031/viewer/2022022413/58eeee4b1a28abe65b8b45f3/html5/thumbnails/40.jpg)
Readability
photo: Morgenland
![Page 41: “Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yorkshire](https://reader031.vdocuments.site/reader031/viewer/2022022413/58eeee4b1a28abe65b8b45f3/html5/thumbnails/41.jpg)
photo by: boston_public_library
Object Calisthenics
Jeff Bay
![Page 42: “Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yorkshire](https://reader031.vdocuments.site/reader031/viewer/2022022413/58eeee4b1a28abe65b8b45f3/html5/thumbnails/42.jpg)
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
![Page 43: “Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yorkshire](https://reader031.vdocuments.site/reader031/viewer/2022022413/58eeee4b1a28abe65b8b45f3/html5/thumbnails/43.jpg)
These are exercises, not rules.
photo by: david_a_l
![Page 44: “Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yorkshire](https://reader031.vdocuments.site/reader031/viewer/2022022413/58eeee4b1a28abe65b8b45f3/html5/thumbnails/44.jpg)
#1 Only one indentation level per method.
photo by: justinliew
![Page 45: “Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yorkshire](https://reader031.vdocuments.site/reader031/viewer/2022022413/58eeee4b1a28abe65b8b45f3/html5/thumbnails/45.jpg)
#2 Do not use else
photo by: justinliew
![Page 46: “Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yorkshire](https://reader031.vdocuments.site/reader031/viewer/2022022413/58eeee4b1a28abe65b8b45f3/html5/thumbnails/46.jpg)
public function createPost($request) { $entity = new Post(); $form = new MyForm($entity); $form->bind($request); if ($form->isValid()){ $repository = $this->getRepository('MyBundle:Post'); if (!$repository->exists($entity) ) { $repository->save($entity); return $this->redirect('create_ok'); } else { $error = "Post Title already exists"; return array('form' => $form, 'error' => $error); } } else { $error = "Invalid fields"; return array('form' => $form, 'error' => $error); } }
![Page 47: “Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yorkshire](https://reader031.vdocuments.site/reader031/viewer/2022022413/58eeee4b1a28abe65b8b45f3/html5/thumbnails/47.jpg)
public function createPost($request) { $entity = new Post(); $form = new MyForm($entity); $form->bind($request); if ($form->isValid()){ $repository = $this->getRepository('MyBundle:Post'); if (!$repository->exists($entity) ) { $repository->save($entity); return $this->redirect('create_ok'); } else { $error = "Post Title already exists"; return array('form' => $form, 'error' => $error); } } else { $error = "Invalid fields"; return array('form' => $form, 'error' => $error); } }
actual goal of function “Create Post"
![Page 48: “Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yorkshire](https://reader031.vdocuments.site/reader031/viewer/2022022413/58eeee4b1a28abe65b8b45f3/html5/thumbnails/48.jpg)
public function createPost($request) { $entity = new Post(); $form = new MyForm($entity); $form->bind($request); if ($form->isValid()){ $repository = $this->getRepository('MyBundle:Post'); if (!$repository->exists($entity) ) { $repository->save($entity); return $this->redirect('create_ok'); } else { $error = "Post Title already exists"; return array('form' => $form, 'error' => $error); } } else { $error = "Invalid fields"; return array('form' => $form, 'error' => $error); } }
this is all error
handling
![Page 49: “Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yorkshire](https://reader031.vdocuments.site/reader031/viewer/2022022413/58eeee4b1a28abe65b8b45f3/html5/thumbnails/49.jpg)
public function createPost($request) { $entity = new Post(); $form = new MyForm($entity); $form->bind($request); if ($form->isValid()){ $repository = $this->getRepository('MyBundle:Post'); if (!$repository->exists($entity) ) { $repository->save($entity); return $this->redirect('create_ok'); } else { $error = "Post Title already exists"; return array('form' => $form, 'error' => $error); } } else { $error = "Invalid fields"; return array('form' => $form, 'error' => $error); } }
![Page 50: “Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yorkshire](https://reader031.vdocuments.site/reader031/viewer/2022022413/58eeee4b1a28abe65b8b45f3/html5/thumbnails/50.jpg)
public function createPost($request) { $entity = new Post(); $repository = $this->getRepository('MyBundle:Post'); $form = new MyForm($entity); $form->bind($request); if ($form->isValid() === false){ return array('form' => $form, 'error' => 'Invalid fields'); } if ($repository->exists($entity)){ return array('form' => $form, 'error' => 'Duplicate post title'); } $repository->save($entity); return $this->redirect('create_ok'); }
![Page 51: “Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yorkshire](https://reader031.vdocuments.site/reader031/viewer/2022022413/58eeee4b1a28abe65b8b45f3/html5/thumbnails/51.jpg)
public function createPost($request) { $entity = new Post(); $repository = $this->getRepository('MyBundle:Post'); $form = new MyForm($entity); $form->bind($request); if ($form->isValid() === false){ return array('form' => $form, 'error' => 'Invalid fields'); } if ($repository->exists($entity)){ return array('form' => $form, 'error' => 'Duplicate post title'); } $repository->save($entity); return $this->redirect('create_ok'); }
exit condition 1: invalid form
![Page 52: “Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yorkshire](https://reader031.vdocuments.site/reader031/viewer/2022022413/58eeee4b1a28abe65b8b45f3/html5/thumbnails/52.jpg)
public function createPost($request) { $entity = new Post(); $repository = $this->getRepository('MyBundle:Post'); $form = new MyForm($entity); $form->bind($request); if ($form->isValid() === false){ return array('form' => $form, 'error' => 'Invalid fields'); } if ($repository->exists($entity)){ return array('form' => $form, 'error' => 'Duplicate post title'); } $repository->save($entity); return $this->redirect('create_ok'); }
exit condition 2: duplicated post
![Page 53: “Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yorkshire](https://reader031.vdocuments.site/reader031/viewer/2022022413/58eeee4b1a28abe65b8b45f3/html5/thumbnails/53.jpg)
public function createPost($request) { $entity = new Post(); $repository = $this->getRepository('MyBundle:Post'); $form = new MyForm($entity); $form->bind($request); if ($form->isValid() === false){ return array('form' => $form, 'error' => 'Invalid fields'); } if ($repository->exists($entity)){ return array('form' => $form, 'error' => 'Duplicate post title'); } $repository->save($entity); return $this->redirect('create_ok'); }
this is what the method actually
does
![Page 54: “Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yorkshire](https://reader031.vdocuments.site/reader031/viewer/2022022413/58eeee4b1a28abe65b8b45f3/html5/thumbnails/54.jpg)
public function createPost($request) { $repository = $this->getRepository('MyBundle:Post'); $entity = new Post();
$repository->save($entity); return $this->redirect('create_ok'); }
![Page 55: “Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yorkshire](https://reader031.vdocuments.site/reader031/viewer/2022022413/58eeee4b1a28abe65b8b45f3/html5/thumbnails/55.jpg)
public function createPost($request) { $repository = $this->getRepository('MyBundle:Post'); $entity = new Post();
$repository->save($entity); return $this->redirect('create_ok'); }
FormValidationMiddleware
UniqueEntityMiddleware
![Page 56: “Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yorkshire](https://reader031.vdocuments.site/reader031/viewer/2022022413/58eeee4b1a28abe65b8b45f3/html5/thumbnails/56.jpg)
public function createPost($request) { $repository = $this->getRepository('MyBundle:Post'); $entity = new Post();
$repository->save($entity); return $this->redirect('create_ok'); }
The power of PSR-7 and middleware
FormValidationMiddleware
UniqueEntityMiddleware
![Page 57: “Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yorkshire](https://reader031.vdocuments.site/reader031/viewer/2022022413/58eeee4b1a28abe65b8b45f3/html5/thumbnails/57.jpg)
![Page 58: “Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yorkshire](https://reader031.vdocuments.site/reader031/viewer/2022022413/58eeee4b1a28abe65b8b45f3/html5/thumbnails/58.jpg)
![Page 59: “Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yorkshire](https://reader031.vdocuments.site/reader031/viewer/2022022413/58eeee4b1a28abe65b8b45f3/html5/thumbnails/59.jpg)
#3 Wrap primitive types, if they contain behavior
photo by: justinliew
![Page 60: “Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yorkshire](https://reader031.vdocuments.site/reader031/viewer/2022022413/58eeee4b1a28abe65b8b45f3/html5/thumbnails/60.jpg)
$component->repaint(false);
![Page 61: “Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yorkshire](https://reader031.vdocuments.site/reader031/viewer/2022022413/58eeee4b1a28abe65b8b45f3/html5/thumbnails/61.jpg)
$component->repaint( new Animate(false) );
![Page 62: “Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yorkshire](https://reader031.vdocuments.site/reader031/viewer/2022022413/58eeee4b1a28abe65b8b45f3/html5/thumbnails/62.jpg)
#4 Only one -> per line
photo by: justinliew
![Page 63: “Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yorkshire](https://reader031.vdocuments.site/reader031/viewer/2022022413/58eeee4b1a28abe65b8b45f3/html5/thumbnails/63.jpg)
#5 Do not abbreviate.
photo by: justinliew
![Page 64: “Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yorkshire](https://reader031.vdocuments.site/reader031/viewer/2022022413/58eeee4b1a28abe65b8b45f3/html5/thumbnails/64.jpg)
if($sx >= $sy) { if ($sx > $strSysMatImgW) { $ny = $strSysMatImgW * $sy / $sx; $nx = $strSysMatImgW; } if ($ny > $strSysMatImgH) { $nx = $strSysMatImgH * $sx / $sy; $ny = $strSysMatImgH; }
}
![Page 65: “Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yorkshire](https://reader031.vdocuments.site/reader031/viewer/2022022413/58eeee4b1a28abe65b8b45f3/html5/thumbnails/65.jpg)
#6 Keep your classes small.
photo by: justinliew
![Page 66: “Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yorkshire](https://reader031.vdocuments.site/reader031/viewer/2022022413/58eeee4b1a28abe65b8b45f3/html5/thumbnails/66.jpg)
#7 Limit your instance variables to 2
photo by: justinliew
![Page 67: “Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yorkshire](https://reader031.vdocuments.site/reader031/viewer/2022022413/58eeee4b1a28abe65b8b45f3/html5/thumbnails/67.jpg)
#8 Use first class collections
photo by: justinliew
![Page 68: “Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yorkshire](https://reader031.vdocuments.site/reader031/viewer/2022022413/58eeee4b1a28abe65b8b45f3/html5/thumbnails/68.jpg)
#9 Don’t use getters and setters.
photo by: justinliew
![Page 69: “Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yorkshire](https://reader031.vdocuments.site/reader031/viewer/2022022413/58eeee4b1a28abe65b8b45f3/html5/thumbnails/69.jpg)
public function getScore($request) { return $this->score;}
public function setScore($score) { $this->score = $score;}
$game->setScore($game->getScore() += 1);
![Page 70: “Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yorkshire](https://reader031.vdocuments.site/reader031/viewer/2022022413/58eeee4b1a28abe65b8b45f3/html5/thumbnails/70.jpg)
public function collectedCoin() { $this->score += 1;}
$game->collectedCoin();
![Page 71: “Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yorkshire](https://reader031.vdocuments.site/reader031/viewer/2022022413/58eeee4b1a28abe65b8b45f3/html5/thumbnails/71.jpg)
#10 Document your code.
photo by: justinliew
![Page 72: “Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yorkshire](https://reader031.vdocuments.site/reader031/viewer/2022022413/58eeee4b1a28abe65b8b45f3/html5/thumbnails/72.jpg)
Your turn.
![Page 73: “Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yorkshire](https://reader031.vdocuments.site/reader031/viewer/2022022413/58eeee4b1a28abe65b8b45f3/html5/thumbnails/73.jpg)
Improve yourself!
![Page 74: “Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yorkshire](https://reader031.vdocuments.site/reader031/viewer/2022022413/58eeee4b1a28abe65b8b45f3/html5/thumbnails/74.jpg)
Read lots of code!
![Page 75: “Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yorkshire](https://reader031.vdocuments.site/reader031/viewer/2022022413/58eeee4b1a28abe65b8b45f3/html5/thumbnails/75.jpg)
Write simpler code.
![Page 76: “Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yorkshire](https://reader031.vdocuments.site/reader031/viewer/2022022413/58eeee4b1a28abe65b8b45f3/html5/thumbnails/76.jpg)
Try Object Calisthenics for a month.
![Page 77: “Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yorkshire](https://reader031.vdocuments.site/reader031/viewer/2022022413/58eeee4b1a28abe65b8b45f3/html5/thumbnails/77.jpg)
Use someone else’s code,
and share yours!
![Page 78: “Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yorkshire](https://reader031.vdocuments.site/reader031/viewer/2022022413/58eeee4b1a28abe65b8b45f3/html5/thumbnails/78.jpg)
Improve your naming, secure your API, grow
awesome teams, handle errors, flip out, check out
MySQL 8, Drupal 8 and HTML 5, go PSR-7, git you guts and finally, survive.
#phpyorkshire
![Page 79: “Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yorkshire](https://reader031.vdocuments.site/reader031/viewer/2022022413/58eeee4b1a28abe65b8b45f3/html5/thumbnails/79.jpg)
Improve your naming, secure your API, grow
awesome teams, handle errors, flip out, check out
MySQL 8, Drupal 8 and HTML 5, go PSR-7, git you guts and finally, survive.
#phpyorkshire
![Page 80: “Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yorkshire](https://reader031.vdocuments.site/reader031/viewer/2022022413/58eeee4b1a28abe65b8b45f3/html5/thumbnails/80.jpg)
Thank you.
http://slides.doh.ms
http://doh.ms
@rdohms
https://joind.in/talk/89356
jobs.usabilla.comlooking for a job in Amsterdam?
![Page 81: “Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yorkshire](https://reader031.vdocuments.site/reader031/viewer/2022022413/58eeee4b1a28abe65b8b45f3/html5/thumbnails/81.jpg)
http://l.doh.ms/oc-material
Video recording
Slides
Books
Resources on Object Calisthenics