Code is read many mor times than written - short
-
Upload
tobias-pfeiffer -
Category
Technology
-
view
112 -
download
2
description
Transcript of Code is read many mor times than written - short
![Page 1: Code is read many mor times than written - short](https://reader034.fdocuments.in/reader034/viewer/2022051400/54c6714f4a795913618b4674/html5/thumbnails/1.jpg)
We write code
![Page 2: Code is read many mor times than written - short](https://reader034.fdocuments.in/reader034/viewer/2022051400/54c6714f4a795913618b4674/html5/thumbnails/2.jpg)
Isn't it more aboutreading?
![Page 3: Code is read many mor times than written - short](https://reader034.fdocuments.in/reader034/viewer/2022051400/54c6714f4a795913618b4674/html5/thumbnails/3.jpg)
Written once – read many times
![Page 4: Code is read many mor times than written - short](https://reader034.fdocuments.in/reader034/viewer/2022051400/54c6714f4a795913618b4674/html5/thumbnails/4.jpg)
„(…) when you program, you have to think about how someone will read your code, not just how a computer will interpret it.“Kent Beck
![Page 5: Code is read many mor times than written - short](https://reader034.fdocuments.in/reader034/viewer/2022051400/54c6714f4a795913618b4674/html5/thumbnails/5.jpg)
Not about Architecture
![Page 6: Code is read many mor times than written - short](https://reader034.fdocuments.in/reader034/viewer/2022051400/54c6714f4a795913618b4674/html5/thumbnails/6.jpg)
Methods & Code
![Page 7: Code is read many mor times than written - short](https://reader034.fdocuments.in/reader034/viewer/2022051400/54c6714f4a795913618b4674/html5/thumbnails/7.jpg)
Extra effort
![Page 8: Code is read many mor times than written - short](https://reader034.fdocuments.in/reader034/viewer/2022051400/54c6714f4a795913618b4674/html5/thumbnails/8.jpg)
Save time
![Page 9: Code is read many mor times than written - short](https://reader034.fdocuments.in/reader034/viewer/2022051400/54c6714f4a795913618b4674/html5/thumbnails/9.jpg)
Your code base?
![Page 10: Code is read many mor times than written - short](https://reader034.fdocuments.in/reader034/viewer/2022051400/54c6714f4a795913618b4674/html5/thumbnails/10.jpg)
![Page 11: Code is read many mor times than written - short](https://reader034.fdocuments.in/reader034/viewer/2022051400/54c6714f4a795913618b4674/html5/thumbnails/11.jpg)
It's about joy!
![Page 12: Code is read many mor times than written - short](https://reader034.fdocuments.in/reader034/viewer/2022051400/54c6714f4a795913618b4674/html5/thumbnails/12.jpg)
Code is read many more times than written
Tobias Pfeiffer@PragTob
pragtob.info
![Page 13: Code is read many mor times than written - short](https://reader034.fdocuments.in/reader034/viewer/2022051400/54c6714f4a795913618b4674/html5/thumbnails/13.jpg)
Sources
![Page 14: Code is read many mor times than written - short](https://reader034.fdocuments.in/reader034/viewer/2022051400/54c6714f4a795913618b4674/html5/thumbnails/14.jpg)
Crazy?
![Page 15: Code is read many mor times than written - short](https://reader034.fdocuments.in/reader034/viewer/2022051400/54c6714f4a795913618b4674/html5/thumbnails/15.jpg)
Are comments a smell?
![Page 16: Code is read many mor times than written - short](https://reader034.fdocuments.in/reader034/viewer/2022051400/54c6714f4a795913618b4674/html5/thumbnails/16.jpg)
Outdated comments are the worst
![Page 17: Code is read many mor times than written - short](https://reader034.fdocuments.in/reader034/viewer/2022051400/54c6714f4a795913618b4674/html5/thumbnails/17.jpg)
The why not the what
![Page 18: Code is read many mor times than written - short](https://reader034.fdocuments.in/reader034/viewer/2022051400/54c6714f4a795913618b4674/html5/thumbnails/18.jpg)
Comments are an excuse of the code that it could not be
clearer.
![Page 19: Code is read many mor times than written - short](https://reader034.fdocuments.in/reader034/viewer/2022051400/54c6714f4a795913618b4674/html5/thumbnails/19.jpg)
# do one thing………
# do another thing………
# do something more……
![Page 20: Code is read many mor times than written - short](https://reader034.fdocuments.in/reader034/viewer/2022051400/54c6714f4a795913618b4674/html5/thumbnails/20.jpg)
Extract Methods
![Page 21: Code is read many mor times than written - short](https://reader034.fdocuments.in/reader034/viewer/2022051400/54c6714f4a795913618b4674/html5/thumbnails/21.jpg)
do_one_thingdo_another_thingdo_something_more
![Page 22: Code is read many mor times than written - short](https://reader034.fdocuments.in/reader034/viewer/2022051400/54c6714f4a795913618b4674/html5/thumbnails/22.jpg)
# context, outlet, times, time per step, state, datadef pattern(c, o, t, l, s, d) # …end
![Page 23: Code is read many mor times than written - short](https://reader034.fdocuments.in/reader034/viewer/2022051400/54c6714f4a795913618b4674/html5/thumbnails/23.jpg)
Explanatory and meaningful names
![Page 24: Code is read many mor times than written - short](https://reader034.fdocuments.in/reader034/viewer/2022051400/54c6714f4a795913618b4674/html5/thumbnails/24.jpg)
def pattern(context, outlet, time, time_per_step, state, data) # …end
![Page 25: Code is read many mor times than written - short](https://reader034.fdocuments.in/reader034/viewer/2022051400/54c6714f4a795913618b4674/html5/thumbnails/25.jpg)
Try to keep it to 2 parameters
![Page 26: Code is read many mor times than written - short](https://reader034.fdocuments.in/reader034/viewer/2022051400/54c6714f4a795913618b4674/html5/thumbnails/26.jpg)
Short Methods (<= 8 LOC)
![Page 27: Code is read many mor times than written - short](https://reader034.fdocuments.in/reader034/viewer/2022051400/54c6714f4a795913618b4674/html5/thumbnails/27.jpg)
# allowed to drink?if customer.age > 18 say 'Okay' prepare_drink requested_drink say 'here you go' hand_drink_over drink, customerelse say 'I am sorry you are not legally allowed rather to drink here' say "Would you rather have a #{NON_ALCOHOLIC_DRINKS.sample}?"end
![Page 28: Code is read many mor times than written - short](https://reader034.fdocuments.in/reader034/viewer/2022051400/54c6714f4a795913618b4674/html5/thumbnails/28.jpg)
if customer.age > 18 say 'Okay' prepare_drink requested_drink say 'here you go' hand_drink_over drink, customerelse say 'I am sorry you are not legally allowed rather to drink here' say "Would you rather have a #{NON_ALCOHOLIC_DRINKS.sample}?"end
![Page 29: Code is read many mor times than written - short](https://reader034.fdocuments.in/reader034/viewer/2022051400/54c6714f4a795913618b4674/html5/thumbnails/29.jpg)
if customer.age > 18 say 'Okay' prepare_drink requested_drink say 'here you go' hand_drink_over drink, customerelse say 'I am sorry you are not legally allowed rather to drink here' say "Would you rather have a #{NON_ALCOHOLIC_DRINKS.sample}?"end
![Page 30: Code is read many mor times than written - short](https://reader034.fdocuments.in/reader034/viewer/2022051400/54c6714f4a795913618b4674/html5/thumbnails/30.jpg)
if customer.age > 18 say 'Okay' prepare_drink requested_drink say 'here you go' hand_drink_over drink, customerelse say 'I am sorry you are not legally allowed rather to drink here' say "Would you rather have a #{NON_ALCOHOLIC_DRINKS.sample}?"end
![Page 31: Code is read many mor times than written - short](https://reader034.fdocuments.in/reader034/viewer/2022051400/54c6714f4a795913618b4674/html5/thumbnails/31.jpg)
if allowed_to_drink_alcohol?(customer) serve_drink requested_drink, customerelse propose_non_alcoholic_drinkend
![Page 32: Code is read many mor times than written - short](https://reader034.fdocuments.in/reader034/viewer/2022051400/54c6714f4a795913618b4674/html5/thumbnails/32.jpg)
Nice code formatting
![Page 33: Code is read many mor times than written - short](https://reader034.fdocuments.in/reader034/viewer/2022051400/54c6714f4a795913618b4674/html5/thumbnails/33.jpg)
@left ||= 0 @top ||= 0 @width ||= 1.0 @height ||= 0
![Page 34: Code is read many mor times than written - short](https://reader034.fdocuments.in/reader034/viewer/2022051400/54c6714f4a795913618b4674/html5/thumbnails/34.jpg)
double character: 'something weird', stateMask: CTRL | modifier, KeyCode: character.downcase.ord
![Page 35: Code is read many mor times than written - short](https://reader034.fdocuments.in/reader034/viewer/2022051400/54c6714f4a795913618b4674/html5/thumbnails/35.jpg)
80 characterWidth limit
![Page 36: Code is read many mor times than written - short](https://reader034.fdocuments.in/reader034/viewer/2022051400/54c6714f4a795913618b4674/html5/thumbnails/36.jpg)
80 characterWidth limit
![Page 37: Code is read many mor times than written - short](https://reader034.fdocuments.in/reader034/viewer/2022051400/54c6714f4a795913618b4674/html5/thumbnails/37.jpg)
80 characterWidth limit
![Page 38: Code is read many mor times than written - short](https://reader034.fdocuments.in/reader034/viewer/2022051400/54c6714f4a795913618b4674/html5/thumbnails/38.jpg)
80 characterWidth limit
![Page 39: Code is read many mor times than written - short](https://reader034.fdocuments.in/reader034/viewer/2022051400/54c6714f4a795913618b4674/html5/thumbnails/39.jpg)
80 characterWidth limit
![Page 40: Code is read many mor times than written - short](https://reader034.fdocuments.in/reader034/viewer/2022051400/54c6714f4a795913618b4674/html5/thumbnails/40.jpg)
Code bases detoriate
![Page 41: Code is read many mor times than written - short](https://reader034.fdocuments.in/reader034/viewer/2022051400/54c6714f4a795913618b4674/html5/thumbnails/41.jpg)
No broken windows
![Page 42: Code is read many mor times than written - short](https://reader034.fdocuments.in/reader034/viewer/2022051400/54c6714f4a795913618b4674/html5/thumbnails/42.jpg)
![Page 43: Code is read many mor times than written - short](https://reader034.fdocuments.in/reader034/viewer/2022051400/54c6714f4a795913618b4674/html5/thumbnails/43.jpg)
![Page 44: Code is read many mor times than written - short](https://reader034.fdocuments.in/reader034/viewer/2022051400/54c6714f4a795913618b4674/html5/thumbnails/44.jpg)
Magical time?
![Page 45: Code is read many mor times than written - short](https://reader034.fdocuments.in/reader034/viewer/2022051400/54c6714f4a795913618b4674/html5/thumbnails/45.jpg)
The BoyscoutRule
![Page 46: Code is read many mor times than written - short](https://reader034.fdocuments.in/reader034/viewer/2022051400/54c6714f4a795913618b4674/html5/thumbnails/46.jpg)
![Page 47: Code is read many mor times than written - short](https://reader034.fdocuments.in/reader034/viewer/2022051400/54c6714f4a795913618b4674/html5/thumbnails/47.jpg)
TDD
![Page 48: Code is read many mor times than written - short](https://reader034.fdocuments.in/reader034/viewer/2022051400/54c6714f4a795913618b4674/html5/thumbnails/48.jpg)
Know when tobreak the rules
![Page 49: Code is read many mor times than written - short](https://reader034.fdocuments.in/reader034/viewer/2022051400/54c6714f4a795913618b4674/html5/thumbnails/49.jpg)
If you still like your code from two years ago,
then you are not learning fast enough.
![Page 51: Code is read many mor times than written - short](https://reader034.fdocuments.in/reader034/viewer/2022051400/54c6714f4a795913618b4674/html5/thumbnails/51.jpg)
Sources
● The Pragmatic Programmer● Smalltalk Best Practice Patterns● Clean Code● Practical Object Oriented Design in Ruby
![Page 52: Code is read many mor times than written - short](https://reader034.fdocuments.in/reader034/viewer/2022051400/54c6714f4a795913618b4674/html5/thumbnails/52.jpg)
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/7658272558/in/photostream/
– http://www.flickr.com/photos/83633410@N07/7658165122/
– http://en.wikipedia.org/wiki/File:Kent_Beck_no_Workshop_Mapping_XP.jpg
● (CC BY-NC-ND 2.0)
– http://www.flickr.com/photos/andih/86577529/
– http://www.flickr.com/photos/12584908@N08/3293117576/
– http://www.flickr.com/photos/jasonlparks/4525188865/
– 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/barry_b/76055201/
– http://www.flickr.com/photos/25165196@N08/7725273678/
– http://www.flickr.com/photos/29254399@N08/3187186308/
● (CC BY-NC-SA 2.0)
– http://www.flickr.com/photos/dolescum/7380616658/
– http://www.flickr.com/photos/antonkovalyov/5795281215/
– 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/
![Page 53: Code is read many mor times than written - short](https://reader034.fdocuments.in/reader034/viewer/2022051400/54c6714f4a795913618b4674/html5/thumbnails/53.jpg)
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