Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Clean Code in practice

Sponsored · Ship Features Fearlessly Turn features on and off without deploys. Used by thousands of Ruby developers. →

Clean Code in practice

"Continuous attention to technical excellence and good design enhances agility." 9th principle of Agile Manifesto.

Why is it so important to take care of code cleanness ? What are the major "code smells" which taint our code ? And how to clean or avoid them? Come find some answers to these questions (live code inside :).

ITAKE Unconference, Bucharest, 2013. http://www.itakeunconf.com

Avatar for Antoine

Antoine

May 31, 2013

More Decks by Antoine

Other Decks in Programming

Transcript

  1. DISCLAIMER Object Oriented Language I won't go into details Some

    points will look stupidly simple I will repeat myself
  2. AGILE & QUALITY Continuous attention to technical excellence and good

    design enhances agility. Agile Manifesto, 9th principle
  3. WHAT IS QUALITY ? A software is of good quality

    if the cost to add a feature does not change over time. Jérôme Avoustin
  4. WHAT IS A CLEAN CODE ? Clean code is not

    about beautifullness, it's about goodness. Rebecca Wirfs-Brock tested ! no duplication reveals its intention easy to read B. Stroustrup, R. Jeffries, K. Beck, M. Feathers, W. Cunningham, ...
  5. GOOD NAMING names should reveal the intent alt+shift+r is your

    friend (in eclipse) ... LET'S SEE FOR REAL.
  6. ABSTRACTION DEMETER'S LAW DON'T TALK TO STRANGER a . g

    e t B ( ) . g e t C ( ) . d o T h i n g s ( ) ;
  7. DEPENDANCY INJECTION p u b l i c c l

    a s s A { p r i v a t e B b ; p u b l i c v o i d e x e c u t e ( i n t i ) { b = n e w B ( ) ; C c = n e w C ( ) ; i f ( i < = 3 ) { b . e x e c u t e B ( ) ; } e l s e { c . e x e c u t e C ( ) ; } } }
  8. COMMENTS Comments are always failure Uncle Bob Don't comment bad

    code. Rewrite it. Brian W. Kernighan, P.J. Plaugher
  9. COMMENTS FROM REAL LIFE / * * A c o

    m m e n t t o p l e a s e c h e c k s t y l e * / / * * S e t t h e p o r t * * @ p a r a m s p o r t * / p u b l i c v o i d s e t P o r t ( P o r t p o r t ) { t h i s . p o r t = p o r t } . . . } / * e n d f o r * / d a o . f l u s h ( ) ; d e f a u l t : b r e a k ; } / * e n d s w i t c h * / } / * e n d i f * / } / * e n d i f * / } c a t c h . . .
  10. HANDLING EXCEPTION FAIL FAST 1. Do not check exception 2.

    Manage exception as high as possible 3. Never ever return null !
  11. TESTS The give you confidence to change the code. one

    test, one assert readibility tests document your code A TEST SHOULD TELL YOU A STORY TESTS ARE FIRST CLASS CITIZEN !
  12. SOME MORE ADVICES Don't think inheritance, think polymorphism Don't think

    if/switch, think polymorphism AVOID SINGLETONS Did i warn you i will repeat myself ?
  13. QUOTES Any fool can write code that a computer can

    understand. Good programmers write code that human can understand. Martin Fowler Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live. Martin Golding ...if you're afraid to change something it is clearly poorly designed. Martin Fowler