Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Code is read many mor times than written - short

574 views

Published on

the slides from the 15 minute "Code is read many more times than written" talk I gave at the Rails Girls Berlin workshop on the 15th of February

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Code is read many mor times than written - short

  1. 1. We write code
  2. 2. Isn't it more about reading?
  3. 3. Written once – read many times
  4. 4. „(…) when you program, you have to think about how someone will read your code, not just how a computer will interpret it.“ Kent Beck
  5. 5. Not about Architecture
  6. 6. Methods & Code
  7. 7. Extra effort
  8. 8. Save time
  9. 9. Your code base?
  10. 10. It's about joy!
  11. 11. Code is read many more times than written Tobias Pfeiffer @PragTob pragtob.info
  12. 12. Sources
  13. 13. Crazy?
  14. 14. Are comments a smell?
  15. 15. Outdated comments are the worst
  16. 16. The why not the what
  17. 17. Comments are an excuse of the code that it could not be clearer.
  18. 18. # do one thing … … … # do another thing … … … # do something more … …
  19. 19. Extract Methods
  20. 20. do_one_thing do_another_thing do_something_more
  21. 21. # context, outlet, times, time per step, state, data def pattern(c, o, t, l, s, d) # … end
  22. 22. Explanatory and meaningful names
  23. 23. def pattern(context, outlet, time, time_per_step, state, data) # … end
  24. 24. Try to keep it to 2 parameters
  25. 25. Short Methods (<= 8 LOC)
  26. 26. # allowed to drink? if customer.age > 18 say 'Okay' prepare_drink requested_drink say 'here you go' hand_drink_over drink, customer else say 'I am sorry you are not legally allowed rather to drink here' say "Would you rather have a #{NON_ALCOHOLIC_DRINKS.sample}?" end
  27. 27. if customer.age > 18 say 'Okay' prepare_drink requested_drink say 'here you go' hand_drink_over drink, customer else say 'I am sorry you are not legally allowed rather to drink here' say "Would you rather have a #{NON_ALCOHOLIC_DRINKS.sample}?" end
  28. 28. if customer.age > 18 say 'Okay' prepare_drink requested_drink say 'here you go' hand_drink_over drink, customer else say 'I am sorry you are not legally allowed rather to drink here' say "Would you rather have a #{NON_ALCOHOLIC_DRINKS.sample}?" end
  29. 29. if customer.age > 18 say 'Okay' prepare_drink requested_drink say 'here you go' hand_drink_over drink, customer else say 'I am sorry you are not legally allowed rather to drink here' say "Would you rather have a #{NON_ALCOHOLIC_DRINKS.sample}?" end
  30. 30. if allowed_to_drink_alcohol?(customer) serve_drink requested_drink, customer else propose_non_alcoholic_drink end
  31. 31. Nice code formatting
  32. 32. @left @top @width @height ||= ||= ||= ||= 0 0 1.0 0
  33. 33. double character: 'something weird', stateMask: CTRL | modifier, KeyCode: character.downcase.ord
  34. 34. 80 character Width limit
  35. 35. 80 character Width limit
  36. 36. 80 character Width limit
  37. 37. 80 character Width limit
  38. 38. 80 character Width limit
  39. 39. Code bases detoriate
  40. 40. No broken windows
  41. 41. Magical time?
  42. 42. The Boyscout Rule
  43. 43. TDD
  44. 44. Know when to break the rules
  45. 45. If you still like your code from two years ago, then you are not learning fast enough.
  46. 46. Enjoy Coding! Tobias Pfeiffer @PragTob pragtob.info
  47. 47. Sources ● The Pragmatic Programmer ● Smalltalk Best Practice Patterns ● Clean Code ● Practical Object Oriented Design in Ruby
  48. 48. Photo Credit ● http://officeimg.vo.msecnd.net/en-us/images/MP900439313.jpg ● http://officeimg.vo.msecnd.net/en-us/images/MC900021328.wmf ● (CC BY-SA 2.0) – http://www.flickr.com/photos/83633410@N07/7658165122/ – ● http://www.flickr.com/photos/83633410@N07/7658272558/in/photostream/ – http://en.wikipedia.org/wiki/File:Kent_Beck_no_Workshop_Mapping_XP.jpg (CC BY-NC-ND 2.0) – http://www.flickr.com/photos/jasonlparks/4525188865/ – ● http://www.flickr.com/photos/12584908@N08/3293117576/ – ● http://www.flickr.com/photos/andih/86577529/ – http://www.flickr.com/photos/20714221@N04/2293045156/ http://www.flickr.com/photos/47833351@N02/5488791911/(CC BY-ND 2.0) (CC BY 2.0) – http://www.flickr.com/photos/25165196@N08/7725273678/ – ● http://www.flickr.com/photos/barry_b/76055201/ – http://www.flickr.com/photos/29254399@N08/3187186308/ (CC BY-NC-SA 2.0) – http://www.flickr.com/photos/antonkovalyov/5795281215/ – ● http://www.flickr.com/photos/dolescum/7380616658/ – http://www.flickr.com/photos/doug88888/2792209612/ (CC BY-NC 2.0) – http://www.flickr.com/photos/37996583811@N01/5757983532/ – http://www.flickr.com/photos/sevendead/5650065458/
  49. 49. Source pictures ● http://imagery.pragprog.com/products/59/tpp.jpg ● http://www.informit.com/ShowCover.aspx?isbn=9780132852111&type=f ● http://coding-in.net/blog/wp-content/uploads/clean_code.jpg ● http://www.informit.com/ShowCover.aspx?isbn=9780321721334&type=f ● http://mendicantuniversity.org/images/logo.png

×