Programming for People

Programming for People

638d7e4bb8d455e8149b2f46355c0973?s=128

Samson Ootoovak

June 09, 2013
Tweet

Transcript

  1. Programming for People Created by / Samson Ootoovak @ootoovak

  2. Today I am going to talk about programming

  3. You have spent your time here so far learning how

    to comunicate with computers.
  4. But as you learn more about programming, it is good

    to remember that programming is not just for computers.
  5. When you are programming you are also communicating with people.

  6. Brief History

  7. It used to be very important to comunicate as efficiently

    as possible with a computer.
  8. But as computers got faster and there was more code

    to maintain the focus shifted.
  9. Computers are simple, they're just 1's and 0's!

  10. See simple...

  11. So back to the real world.

  12. In 1952 woman named Grace Hopper wrote the first compiler.

    The was the first step in abstraction away from the 1's and 0's and towards code that was easier for people to read. (Side note: Grace Hopper was also the person the coined the term debugging after finding and removing an actual moth from a computer.)
  13. Fast forward a few years... and now we have programming

    languages like Ruby. “For me, the purpose of life is, at least partly, to have joy. Programmers often feel joy when they can concentrate on the creative side of programming, so Ruby is designed to make programmers happy.” -- Yukihiro Matsumoto (a.k.a. “Matz”), 2000
  14. But even Ruby code can get scary. c l a

    s s R o b o t S e a r c h d e f f i n d _ c u p c a k e ( c u p c a k e _ x , c u p c a k e _ y ) @ r o b o t _ x = 0 @ r o b o t _ y = 0 @ r o b o t _ d i r e c t i o n = 0 @ f o u n d _ c u p c a k e = f a l s e 6 . t i m e s d o @ r o b o t _ x + = 1 @ r o b o t _ y + = 1 e n d i f ( @ r o b o t _ x = = c u p c a k e _ x & & @ r o b o t _ y = = c u p c a k e _ y ) p u t s ' Y o u f o u n d t h e c u p c a k e ! ' @ f o u n d _ c u p c a k e = t r u e e n d u n l e s s ( @ f o u n d _ c u p c a k e ) @ r o b o t _ d i r e c t i o n = 9 0 e n d 6 . t i m e s d o @ r o b o t _ x + = 1 @ r o b o t _ y + = 1 e n d i f ( @ r o b o t _ x = = c u p c a k e _ x & & @ r o b o t _ y = = c u p c a k e _ y ) p u t s ' Y o u f o u n d t h e c u p c a k e ! ' @ f o u n d _ c u p c a k e = t r u e e n d u n l e s s ( @ f o u n d _ c u p c a k e ) @ r o b o t _ d i r e c t i o n = 9 0 e n d i f ( f o u n d _ c u p c a k e ) p u t s " F o u n d c u p c a t e a t p o s i t i o n # { @ r o b o t _ x } , # { @ r o b o t _ y } ! " e l s e p u t s ' I g i v e u p . ' e n d e n d e n d
  15. But a computer understands this code fine, so why does

    it matter?
  16. Well We write programs so we can communicate with computers.

    Also, there are programs everywhere and they all need to be kept up to date. But we write these programs for people to use.
  17. Programming has also become social

  18. Github

  19. Twitter

  20. And when it comes to code we are all standing

    on the shoulders of others.
  21. So even if you are writing code by yourself you

    are still going to have to read other peoples' code And more than likely other people will also be reading your code So now more than ever you are writing code for people.
  22. So how do we code for people?

  23. Object Oriented Programming You have been using this already in

    Rails, yay! When we write objects the goal is to make sure they only do 1 thing When they try to do more than one thing
  24. Then this happens. c l a s s R o

    b o t S e a r c h d e f f i n d _ c u p c a k e ( c u p c a k e _ x , c u p c a k e _ y ) @ r o b o t _ x = 0 @ r o b o t _ y = 0 @ r o b o t _ d i r e c t i o n = 0 @ f o u n d _ c u p c a k e = f a l s e 6 . t i m e s d o @ r o b o t _ x + = 1 @ r o b o t _ y + = 1 e n d i f ( @ r o b o t _ x = = c u p c a k e _ x & & @ r o b o t _ y = = c u p c a k e _ y ) p u t s ' Y o u f o u n d t h e c u p c a k e ! ' @ f o u n d _ c u p c a k e = t r u e e n d u n l e s s ( @ f o u n d _ c u p c a k e ) @ r o b o t _ d i r e c t i o n = 9 0 e n d 6 . t i m e s d o @ r o b o t _ x + = 1 @ r o b o t _ y + = 1 e n d i f ( @ r o b o t _ x = = c u p c a k e _ x & & @ r o b o t _ y = = c u p c a k e _ y ) p u t s ' Y o u f o u n d t h e c u p c a k e ! ' @ f o u n d _ c u p c a k e = t r u e e n d u n l e s s ( @ f o u n d _ c u p c a k e ) @ r o b o t _ d i r e c t i o n = 9 0 e n d i f ( f o u n d _ c u p c a k e ) p u t s " F o u n d c u p c a t e a t p o s i t i o n # { @ r o b o t _ x } , # { @ r o b o t _ y } ! " e l s e p u t s ' I g i v e u p . ' e n d e n d e n d
  25. A programmer named Sandi Metz proposed 4 rules to help

    with this 1. Your class can be no longer than 100 lines of code. 2. Your methods can be no longer than 5 lines of code. 3. You can pass no more than 4 parameters and you can’t just make it one big hash. 4. When a call comes into your Rails controller, you can only instantiate 1 object to do whatever it is that needs to be done.
  26. But don't worry if you didn't get all of that.

  27. We are just going to use rule #2 to help

    fix the large messy code I showed you earlier. Your methods can be no longer than 5 lines of code.
  28. c l a s s R o b o t

    S e a r c h d e f f i n d _ c u p c a k e ( c u p c a k e _ x , c u p c a k e _ y ) @ r o b o t _ x = 0 @ r o b o t _ y = 0 @ r o b o t _ d i r e c t i o n = 0 @ f o u n d _ c u p c a k e = f a l s e 6 . t i m e s d o @ r o b o t _ x + = 1 @ r o b o t _ y + = 1 e n d i f ( @ r o b o t _ x = = c u p c a k e _ x & & @ r o b o t _ y = = c u p c a k e _ y ) p u t s ' Y o u f o u n d t h e c u p c a k e ! ' @ f o u n d _ c u p c a k e = t r u e e n d u n l e s s ( @ f o u n d _ c u p c a k e ) @ r o b o t _ d i r e c t i o n = 9 0 e n d 6 . t i m e s d o @ r o b o t _ x + = 1 @ r o b o t _ y + = 1 e n d i f ( @ r o b o t _ x = = c u p c a k e _ x & & @ r o b o t _ y = = c u p c a k e _ y ) p u t s ' Y o u f o u n d t h e c u p c a k e ! ' @ f o u n d _ c u p c a k e = t r u e e n d u n l e s s ( @ f o u n d _ c u p c a k e ) @ r o b o t _ d i r e c t i o n = 9 0 e n d i f ( f o u n d _ c u p c a k e ) p u t s " F o u n d c u p c a t e a t p o s i t i o n # { @ r o b o t _ x } , # { @ r o b o t _ y } ! " e l s e p u t s ' I g i v e u p . ' e n d e n d e n d
  29. c l a s s R o b o t

    S e a r c h d e f f i n d _ c u p c a k e ( c u p c a k e _ x , c u p c a k e _ y ) p u t _ r o b o t _ a t _ s t a r t i n g _ p o i n t 6 . t i m e s d o @ r o b o t _ x + = i @ r o b o t _ y + = i e n d i f ( @ r o b o t _ x = = c u p c a k e _ x & & @ r o b o t _ y = = c u p c a k e _ y ) p u t s ' Y o u f o u n d t h e c u p c a k e ! ' @ f o u n d _ c u p c a k e = t r u e e n d u n l e s s ( @ f o u n d _ c u p c a k e ) @ r o b o t _ d i r e c t i o n = 9 0 e n d 6 . t i m e s d o @ r o b o t _ x + = 1 @ r o b o t _ y + = 1 e n d i f ( @ r o b o t _ x = = c u p c a k e _ x & & @ r o b o t _ y = = c u p c a k e _ y ) p u t s ' Y o u f o u n d t h e c u p c a k e ! ' @ f o u n d _ c u p c a k e = t r u e e n d u n l e s s ( @ f o u n d _ c u p c a k e ) @ r o b o t _ d i r e c t i o n = 9 0 e n d i f ( f o u n d _ c u p c a k e ) p u t s " F o u n d c u p c a t e a t p o s i t i o n # { @ r o b o t _ x } , # { @ r o b o t _ y } ! " e l s e p u t s ' I g i v e u p . ' e n d e n d d e f p u t _ r o b o t _ a t _ s t a r t i n g _ p o i n t @ r o b o t _ x = 0 @ r o b o t _ y = 0 @ r o b o t _ d i r e c t i o n = 0 @ f o u n d _ c u p c a k e = f a l s e e n d e n d
  30. c l a s s R o b o t

    S e a r c h d e f f i n d _ c u p c a k e ( c u p c a k e _ x , c u p c a k e _ y ) p u t _ r o b o t _ a t _ s t a r t i n g _ p o i n t w a l k _ f o r w a r d _ s t e p s ( 6 ) i f ( @ r o b o t _ x = = c u p c a k e _ x & & @ r o b o t _ y = = c u p c a k e _ y ) p u t s ' Y o u f o u n d t h e c u p c a k e ! ' @ f o u n d _ c u p c a k e = t r u e e n d u n l e s s ( @ f o u n d _ c u p c a k e ) @ r o b o t _ d i r e c t i o n = 9 0 e n d w a l k _ f o r w a r d _ s t e p s ( 6 ) i f ( @ r o b o t _ x = = c u p c a k e _ x & & @ r o b o t _ y = = c u p c a k e _ y ) p u t s ' Y o u f o u n d t h e c u p c a k e ! ' @ f o u n d _ c u p c a k e = t r u e e n d u n l e s s ( @ f o u n d _ c u p c a k e ) @ r o b o t _ d i r e c t i o n = 9 0 e n d i f ( f o u n d _ c u p c a k e ) p u t s " F o u n d c u p c a t e a t p o s i t i o n # { @ r o b o t _ x } , # { @ r o b o t _ y } ! " e l s e p u t s ' I g i v e u p . ' e n d e n d d e f w a l k _ f o r w a r d _ s t e p s ( n u m b e r _ o f _ s t e p s ) n u m b e r _ o f _ s t e p s . t i m e s d o @ r o b o t _ x + = 1 @ r o b o t _ y + = 1 e n d e n d d e f p u t _ r o b o t _ a t _ s t a r t i n g _ p o i n t @ r o b o t _ x = 0 @ r o b o t _ y = 0 @ r o b o t _ d i r e c t i o n = 0 @ f o u n d _ c u p c a k e = f a l s e e n d e n d
  31. c l a s s R o b o t

    S e a r c h d e f f i n d _ c u p c a k e ( c u p c a k e _ x , c u p c a k e _ y ) p u t _ r o b o t _ a t _ s t a r t i n g _ p o i n t w a l k _ f o r w a r d _ s t e p s ( 6 ) c h e c k _ i f _ f o u n d _ c u p c a k e ? ( c u p c a k e _ x , c u p c a k e _ y ) u n l e s s ( @ f o u n d _ c u p c a k e ) @ r o b o t _ d i r e c t i o n = 9 0 e n d w a l k _ f o r w a r d _ s t e p s ( 6 ) c h e c k _ i f _ f o u n d _ c u p c a k e ? ( c u p c a k e _ x , c u p c a k e _ y ) u n l e s s ( @ f o u n d _ c u p c a k e ) @ r o b o t _ d i r e c t i o n = 9 0 e n d i f ( f o u n d _ c u p c a k e ) p u t s " F o u n d c u p c a t e a t p o s i t i o n # { @ r o b o t _ x } , # { @ r o b o t _ y } ! " e l s e p u t s ' I g i v e u p . ' e n d e n d d e f c h e c k _ i f _ f o u n d _ c u p c a k e ? ( c u p c a k e _ x , c u p c a k e _ y ) i f ( @ r o b o t _ x = = c u p c a k e _ x & & @ r o b o t _ y = = c u p c a k e _ y ) p u t s ' Y o u f o u n d t h e c u p c a k e ! ' @ f o u n d _ c u p c a k e = t r u e e n d e n d d e f w a l k _ f o r w a r d _ s t e p s ( n u m b e r _ o f _ s t e p s ) n u m b e r _ o f _ s t e p s . t i m e s d o @ r o b o t _ x + = 1 @ r o b o t _ y + = 1 e n d e n d d e f p u t _ r o b o t _ a t _ s t a r t i n g _ p o i n t @ r o b o t _ x = 0 @ r o b o t _ y = 0 @ r o b o t _ d i r e c t i o n = 0 @ f o u n d _ c u p c a k e = f a l s e e n d e n d
  32. c l a s s R o b o t

    S e a r c h d e f f i n d _ c u p c a k e ( c u p c a k e _ x , c u p c a k e _ y ) p u t _ r o b o t _ a t _ s t a r t i n g _ p o i n t w a l k _ f o r w a r d _ s t e p s ( 6 ) c h e c k _ i f _ f o u n d _ c u p c a k e ? ( c u p c a k e _ x , c u p c a k e _ y ) t u r n _ r i g h t w a l k _ f o r w a r d _ s t e p s ( 6 ) c h e c k _ i f _ f o u n d _ c u p c a k e ? ( c u p c a k e _ x , c u p c a k e _ y ) t u r n _ r i g h t i f ( f o u n d _ c u p c a k e ) p u t s " F o u n d c u p c a t e a t p o s i t i o n # { @ r o b o t _ x } , # { @ r o b o t _ y } ! " e l s e p u t s ' I g i v e u p . ' e n d e n d d e f t u r n _ r i g h t u n l e s s ( @ f o u n d _ c u p c a k e ) @ r o b o t _ d i r e c t i o n = 9 0 e n d e n d d e f c h e c k _ i f _ f o u n d _ c u p c a k e ? ( c u p c a k e _ x , c u p c a k e _ y ) i f ( @ r o b o t _ x = = c u p c a k e _ x & & @ r o b o t _ y = = c u p c a k e _ y ) p u t s ' Y o u f o u n d t h e c u p c a k e ! ' @ f o u n d _ c u p c a k e = t r u e e n d e n d d e f w a l k _ f o r w a r d _ s t e p s ( n u m b e r _ o f _ s t e p s ) n u m b e r _ o f _ s t e p s . t i m e s d o @ r o b o t _ x + = 1 @ r o b o t _ y + = 1 e n d e n d d e f p u t _ r o b o t _ a t _ s t a r t i n g _ p o i n t @ r o b o t _ x = 0 @ r o b o t _ y = 0 @ r o b o t _ d i r e c t i o n = 0 @ f o u n d _ c u p c a k e = f a l s e e n d e n d
  33. c l a s s R o b o t

    S e a r c h d e f f i n d _ c u p c a k e ( c u p c a k e _ x , c u p c a k e _ y ) p u t _ r o b o t _ a t _ s t a r t i n g _ p o i n t w a l k _ f o r w a r d _ s t e p s ( 6 ) c h e c k _ i f _ f o u n d _ c u p c a k e ? ( c u p c a k e _ x , c u p c a k e _ y ) t u r n _ r i g h t w a l k _ f o r w a r d _ s t e p s ( 6 ) c h e c k _ i f _ f o u n d _ c u p c a k e ? ( c u p c a k e _ x , c u p c a k e _ y ) t u r n _ r i g h t y a y _ f o u n d ? ( f o u n d ) e n d d e f y a y _ f o u n d ? ( f o u n d ) i f ( f o u n d _ c u p c a k e ) p u t s " F o u n d c u p c a t e a t p o s i t i o n # { @ r o b o t _ x } , # { @ r o b o t _ y } ! " e l s e p u t s ' I g i v e u p . ' e n d e n d d e f t u r n _ r i g h t u n l e s s ( @ f o u n d _ c u p c a k e ) @ r o b o t _ d i r e c t i o n = 9 0 e n d e n d d e f c h e c k _ i f _ f o u n d _ c u p c a k e ? ( c u p c a k e _ x , c u p c a k e _ y ) i f ( @ r o b o t _ x = = c u p c a k e _ x & & @ r o b o t _ y = = c u p c a k e _ y ) p u t s ' Y o u f o u n d t h e c u p c a k e ! ' @ f o u n d _ c u p c a k e = t r u e e n d e n d d e f w a l k _ f o r w a r d _ s t e p s ( n u m b e r _ o f _ s t e p s ) n u m b e r _ o f _ s t e p s . t i m e s d o @ r o b o t _ x + = 1 @ r o b o t _ y + = 1 e n d e n d d e f p u t _ r o b o t _ a t _ s t a r t i n g _ p o i n t @ r o b o t _ x = 0 @ r o b o t _ y = 0 @ r o b o t _ d i r e c t i o n = 0 @ f o u n d _ c u p c a k e = f a l s e e n d e n d
  34. c l a s s R o b o t

    S e a r c h d e f f i n d _ c u p c a k e ( c u p c a k e _ x , c u p c a k e _ y ) p u t _ r o b o t _ a t _ s t a r t i n g _ p o i n t s e a r c h ( c u p c a k e _ x , c u p c a k e _ y ) s e a r c h ( c u p c a k e _ x , c u p c a k e _ y ) y a y _ f o u n d ? ( f o u n d ) e n d d e f s e a r c h ( c u p c a k e _ x , c u p c a k e _ y ) w a l k _ f o r w a r d _ s t e p s ( 6 ) c h e c k _ i f _ f o u n d _ c u p c a k e ? ( c u p c a k e _ x , c u p c a k e _ y ) t u r n _ r i g h t e n d d e f y a y _ f o u n d ? ( f o u n d ) i f ( f o u n d _ c u p c a k e ) p u t s " F o u n d c u p c a t e a t p o s i t i o n # { @ r o b o t _ x } , # { @ r o b o t _ y } ! " e l s e p u t s ' I g i v e u p . ' e n d e n d d e f t u r n _ r i g h t u n l e s s ( @ f o u n d _ c u p c a k e ) @ r o b o t _ d i r e c t i o n = 9 0 e n d e n d d e f c h e c k _ i f _ f o u n d _ c u p c a k e ? ( c u p c a k e _ x , c u p c a k e _ y ) i f ( @ r o b o t _ x = = c u p c a k e _ x & & @ r o b o t _ y = = c u p c a k e _ y ) p u t s ' Y o u f o u n d t h e c u p c a k e ! ' @ f o u n d _ c u p c a k e = t r u e e n d e n d d e f w a l k _ f o r w a r d _ s t e p s ( n u m b e r _ o f _ s t e p s ) n u m b e r _ o f _ s t e p s . t i m e s d o @ r o b o t _ x + = 1 @ r o b o t _ y + = 1 e n d e n d d e f p u t _ r o b o t _ a t _ s t a r t i n g _ p o i n t @ r o b o t _ x = 0 @ r o b o t _ y = 0 @ r o b o t _ d i r e c t i o n = 0 @ f o u n d _ c u p c a k e = f a l s e e n d e n d
  35. c l a s s R o b o t

    S e a r c h d e f f i n d _ c u p c a k e ( c u p c a k e _ x , c u p c a k e _ y ) p u t _ r o b o t _ a t _ s t a r t i n g _ p o i n t s e a r c h ( c u p c a k e _ x , c u p c a k e _ y ) s e a r c h ( c u p c a k e _ x , c u p c a k e _ y ) y a y _ f o u n d ? ( f o u n d ) e n d d e f s e a r c h ( c u p c a k e _ x , c u p c a k e _ y ) w a l k _ f o r w a r d _ s t e p s ( 6 ) c h e c k _ i f _ f o u n d _ c u p c a k e ? ( c u p c a k e _ x , c u p c a k e _ y ) t u r n _ r i g h t e n d e n d
  36. None
  37. Thank you for your time

  38. Talk inspired by Sandi Metz ( ), Katrina Owen (

    ), and Avdi Grimm ( ) You can find me on Twitter , on Github at and these slides on Speaker Deck here @sandimetz @kytrinyx @avdi @ootoovak https://github.com/ootoovak https://speakerdeck.com/ootoovak