Top Banner
Writing code that lasts. Rafael Dohms @rdohms photo: djandyw.com #ocforphp
70

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

Apr 16, 2017

Download

Software

Rafael Dohms
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: “Writing code that lasts” … or writing code you won’t hate tomorrow.

Writing code that lasts.

Rafael Dohms@rdohms

photo: djandyw.com

#ocforphp

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

Writing code you won’t hate tomorrow.

Rafael Dohms@rdohms

photo: djandyw.com

#ocforphp

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

Let me introduce you to someone…

Page 4: “Writing code that lasts” … or writing code you won’t hate tomorrow.
Page 5: “Writing code that lasts” … or writing code you won’t hate tomorrow.
Page 6: “Writing code that lasts” … or writing code you won’t hate tomorrow.

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

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

photo: Rob Allen (@akrabat)

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

REWRITEALL THE CODE!

image: hyperboleandahalf

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

Real Developers, SHIP STUFF.

photo: Glyn Lowe Photoworks

Page 11: “Writing code that lasts” … or writing code you won’t hate tomorrow.
Page 12: “Writing code that lasts” … or writing code you won’t hate tomorrow.
Page 13: “Writing code that lasts” … or writing code you won’t hate tomorrow.
Page 14: “Writing code that lasts” … or writing code you won’t hate tomorrow.

How do we find balance?

photo: Kalexanderson

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

Code has an expiration date

photo: CarbonNYC

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

Code is perishable, it rots.

photo by: massdistraction

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

Code Evolves

photo by: kevin dooley

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

Languages evolve.photo by: raneko

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

You evolve.

photo by: Kaptain Kobold

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

Complexity kills Comprehension

photo: osbornb

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

Bad Design

photo: miskan

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

Bad specs

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

NIH

source: Urban dictionary

photo by: John 'K'

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

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 25: “Writing code that lasts” … or writing code you won’t hate tomorrow.

The Solution™photo: Ian Sane

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

Improve code

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

Improve codemake it easier to comprehend

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

Improve codemake it easier to comprehend

make it flexible

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

Improve codemake it easier to comprehend

make it flexible

make it tested

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

Improve codemake it easier to comprehend

make it flexible

make it tested

make it easier to replace, refactor

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

Improve codemake it easier to comprehend

make it flexible

make it tested

make it easier to replace, refactor

make it not exist

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

Testing

photo by: jeffkrause

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

Good Design Concepts

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

SOLID

Single ResponsibilityOpen and Close

Liskov substitutionInterface SegregationDependency Inversion

photo by j_regan

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

photo by lofink

STUPIDSingleton

Tight CouplingUntestability

Premature OptimizationIndescriptive Naming

Duplication

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

Design Patterns

photo by halloweenstock

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

Composer

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

PIEProudly

InventedElsewhere

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

guzzlehttp/guzzleHTTP client for RESTful API clients

photo by j_regan

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

league/tacticianA flexible CommandBus implementation

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

Readability

photo: Morgenland

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

paragraphs

photo: Trossachs Photography

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

whitespace

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

R&D Team for MIH/Naspers

São PauloCape Town

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

Object Calisthenics

photo by: boston_public_library

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

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 48: “Writing code that lasts” … or writing code you won’t hate tomorrow.

Its about perception, not rules or standards

photo by: david_a_l

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

#1 Only one indentation level per method.

photo by: justinliew

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

#2 Do not use else

photo by: justinliew

Page 51: “Writing code that lasts” … or writing code you won’t hate tomorrow.
Page 52: “Writing code that lasts” … or writing code you won’t hate tomorrow.
Page 53: “Writing code that lasts” … or writing code you won’t hate tomorrow.
Page 54: “Writing code that lasts” … or writing code you won’t hate tomorrow.

#3 Wrap primitive types, if they contain behavior

photo by: justinliew

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

#4 Only one -> per line

photo by: justinliew

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

#5 Do not abbreviate.

photo by: justinliew

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

#6 Keep your classes small.

photo by: justinliew

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

#7 Limit your instance variables to less then 5

photo by: justinliew

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

#8 Use first class collections

photo by: justinliew

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

#9 Use getters and setters.

photo by: justinliew

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

#10 Document your code.

photo by: justinliew

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

Your turn.

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

Improve yourself!

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

Read lots of code!

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

Write simple code.

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

Try Object Calisthenics for a month.

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

Use someone else’s code.

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

Share bite size libraries.

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

Thank you.

http://slides.doh.ms

http://doh.ms

@rdohms

we are hiring!

http://tech.sym.bid/jobs