$30 off During Our Annual Pro Sale. View Details »

Readable Code

John Papa
August 09, 2014

Readable Code

The positive impact authoring readable code can have on your career can be huge. There are some simple techniques you can use to create more readable code that can improve your efficiency and make it easier for your code to be supported across teams. Clean Code is popular and Readable Code takes a look at these concepts in a different light and gives you actionable items to improve your code today. Learn how to make Readable Code by using some of the techniques such as separation of concerns, above the fold, the LIFT principles, commenting, encapsulation, and many more! Is your code readable?

John Papa

August 09, 2014
Tweet

More Decks by John Papa

Other Decks in Technology

Transcript

  1. READABLE  CODE   @john_papa  
    READABLE  CODE
    JOHN  PAPA  
    @JOHN_PAPA

    View Slide

  2. READABLE  CODE   @john_papa  
    HOW  FAST  CAN  YOU  READ  
    YOUR  CODE  ?
    JOHN  PAPA  
    @JOHN_PAPA

    View Slide

  3. READABLE  CODE   @john_papa  

     
     
    How  can  you  enhance  code  if  you  can’t  read  it?  

     
     

    View Slide

  4. READABLE  CODE   @john_papa  

    View Slide

  5. READABLE  CODE   @john_papa  

     
     
    It’s  harder  to  read  code  than  to  write  it.  

     
     
    -­‐  Joel  Spolsky  
    But  Why?

    View Slide

  6. READABLE  CODE   @john_papa  

     
     
    It’s  not  about  clever,  craHy,  arIul,  preJy  code.    
    It’s  about  fast  and  effecLve  communicaLon  and  
    code  quality.  

     
     
    What’s  it  all  About?

    View Slide

  7. READABLE  CODE   @john_papa  
    Who  Cares  for  the  Developer  Behind  You?

     
     

     
     
    Caring  about  your  craH  is  a  good  thing.  Caring  about  
    the  what  happens  aHer  you  deploy  your  code  is  
    beauLful.  

    View Slide

  8. READABLE  CODE   @john_papa  
    What’s  Your  MoKvaKon?
    Time  
    ProducLvity  
    Cost  of  a  Complete  Mess  

    View Slide

  9. READABLE  CODE   @john_papa  

     
     

     
     
      YOUR  BOSS  WON’T  LIKE  THAT  

    View Slide

  10. READABLE  CODE   @john_papa  

     
     
    Deploy  faster,  spend  less,  re-­‐use  more,    
    and  maintain  high  quality.    

     
     

    View Slide

  11. READABLE  CODE   @john_papa  
    Who  is  Code  Intended  For?
    Programs  must  be  wriJen  for  people  to  read,  and  
    only  incidentally  for  machines  to  execute.  
    -­‐  Abelson  &  Sussman,  Structure  and  Interpreta9on  of  Computer  Programs  

     
     

     
     

    View Slide

  12. READABLE  CODE   @john_papa  
    Meaningful  Names  Are  Crucial  to  Read  Speed

    View Slide

  13. READABLE  CODE   @john_papa  
    Crystal  Clear  Names  Promote  Readability

    View Slide

  14. READABLE  CODE   @john_papa  
    DescripKve  Names

    View Slide

  15. READABLE  CODE   @john_papa  
    Can’t  Decipher  within  the  5  Second  Rule

    View Slide

  16. READABLE  CODE   @john_papa  
    IntenKons  are  Clear

    View Slide

  17. READABLE  CODE   @john_papa  

     
     
    Most  important  code  is  instantly  visible  

     
     
    Above  the  Fold

    View Slide

  18. READABLE  CODE   @john_papa  

    View Slide

  19. READABLE  CODE   @john_papa  
    Simple  and  Clear

    View Slide

  20. READABLE  CODE   @john_papa  

    View Slide

  21. READABLE  CODE   @john_papa  

     
     
    Less  than  20  lines  of  code  

     
     
    Small  FuncKons  Are  Readable

    View Slide

  22. READABLE  CODE   @john_papa  
    MISSSPELINGS  ARE  IMPORTANT  

     
     
    What  will  you  find  when  you  search  for  your  code?  

     
     

    View Slide

  23. READABLE  CODE   @john_papa  
    Clarity,  Inconsistent  Naming  and  Spelling

    View Slide

  24. READABLE  CODE   @john_papa  
    Consistent  Naming  and  Spelling  MaSer

    View Slide

  25. READABLE  CODE   @john_papa  
    Pick  One  ConvenKon

    View Slide

  26. READABLE  CODE   @john_papa  

     
     
    People  who  maintain  code  lack  the  author’s  context  

     
     
    CONTEXT  ===  CLARITY  

    View Slide

  27. READABLE  CODE   @john_papa  
    Does  Your  Code  Provide  Context?

    View Slide

  28. READABLE  CODE   @john_papa  
    Explain  Yourself  in  Code,  Not  Comments

    View Slide

  29. READABLE  CODE   @john_papa  
    Self  Describing  Code

    View Slide

  30. READABLE  CODE   @john_papa  
    Replace  Comments  and  Magic  Strings

    View Slide

  31. READABLE  CODE   @john_papa  
    Use  DescripKve  FuncKons  and  Constants

    View Slide

  32. READABLE  CODE   @john_papa  
    Comments  are  noise  when  …
    Outdated  and  incorrect  
    Shoulda  coulda  used  a  variable  or  funcLon  
    Redundant  

    View Slide

  33. READABLE  CODE   @john_papa  
    Comments  are  awesome  when  …
    Warnings  of  Consequences  
    API  DocumentaLon  
    TODO’s  

    View Slide

  34. READABLE  CODE   @john_papa  
    How  Readable  Is  My  Code?
    LocaLng  our  code  is  easy  
    IdenLfy  code  at  a  glance  
    Flat  structure  as  long  as  we  can  
    Try  to  stay  DRY  
    L  
    I  
    F  
    T  

    View Slide

  35. READABLE  CODE   @john_papa  

     
     
    Clean  code  is  the  secret  to    
    your  applicaLon’s  long  and  healthy  life  

     
     

    View Slide

  36. READABLE  CODE   @john_papa  
    Nothing  Starts  Readable

     
      Write  dirty  code,  then  clean  it  

     
     

    View Slide

  37. READABLE  CODE   @john_papa  
    Opinionated  AngularJS  Style  Guide
    hJp://jpapa.me/ngstyles  
     

    View Slide