Slide 1

Slide 1 text

I F JSCONF Argentina, buenos aires, nov 29th, 2014

Slide 2

Slide 2 text

J O K E

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

if  (eggs)  { }

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

W E H AV E A P RO B L E M O B V I O U S LY

Slide 8

Slide 8 text

I F ?

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

E L S E ?

Slide 15

Slide 15 text

I N E N G L I S H B O O K S else If

Slide 16

Slide 16 text

I N C O M P U T E R P R O G R A M S else If

Slide 17

Slide 17 text

I N C O M P U T E R P R O G R A M S else If 2.5 times more else!

Slide 18

Slide 18 text

W H Y ?

Slide 19

Slide 19 text

if  (⩸⩸⩸⩸⩸1)  {      ⩸⩸⩸⩸      ⩸⩸⩸⩸      if  (⩸⩸2)  {          ⩸⩸⩸⩸      }  else  {          ⩸⩸⩸          ⩸⩸⩸⩸⩸⩸          ⩸⩸          if  (⩸⩸⩸3)  {              ⩸⩸          }  else  {              ⩸⩸                    ⩸⩸⩸⩸⩸⩸          }      }   }  else  {      ⩸⩸⩸   }

Slide 20

Slide 20 text

if  (⩸⩸⩸⩸⩸1)  {      ⩸⩸⩸⩸      ⩸⩸⩸⩸      if  (⩸⩸2)  {          ⩸⩸⩸⩸      }  else  {          ⩸⩸⩸          ⩸⩸⩸⩸⩸⩸          ⩸⩸          if  (⩸⩸⩸3)  {              ⩸⩸          }  else  {              ⩸⩸                    ⩸⩸⩸⩸⩸⩸          }      }   }  else  {      ⩸⩸⩸   } 1: true

Slide 21

Slide 21 text

if  (⩸⩸⩸⩸⩸1)  {      ⩸⩸⩸⩸      ⩸⩸⩸⩸      if  (⩸⩸2)  {          ⩸⩸⩸⩸      }  else  {          ⩸⩸⩸          ⩸⩸⩸⩸⩸⩸          ⩸⩸          if  (⩸⩸⩸3)  {              ⩸⩸          }  else  {              ⩸⩸                    ⩸⩸⩸⩸⩸⩸          }      }   }  else  {      ⩸⩸⩸   } 1: true 1: true, 2: true

Slide 22

Slide 22 text

if  (⩸⩸⩸⩸⩸1)  {      ⩸⩸⩸⩸      ⩸⩸⩸⩸      if  (⩸⩸2)  {          ⩸⩸⩸⩸      }  else  {          ⩸⩸⩸          ⩸⩸⩸⩸⩸⩸          ⩸⩸          if  (⩸⩸⩸3)  {              ⩸⩸          }  else  {              ⩸⩸                    ⩸⩸⩸⩸⩸⩸          }      }   }  else  {      ⩸⩸⩸   } 1: true 1: true, 2: true 1: true, 2: false

Slide 23

Slide 23 text

if  (⩸⩸⩸⩸⩸1)  {      ⩸⩸⩸⩸      ⩸⩸⩸⩸      if  (⩸⩸2)  {          ⩸⩸⩸⩸      }  else  {          ⩸⩸⩸          ⩸⩸⩸⩸⩸⩸          ⩸⩸          if  (⩸⩸⩸3)  {              ⩸⩸          }  else  {              ⩸⩸                    ⩸⩸⩸⩸⩸⩸          }      }   }  else  {      ⩸⩸⩸   } 1: true 1: true, 2: true 1: true, 2: false 1: true, 2: false, 3: true

Slide 24

Slide 24 text

if  (⩸⩸⩸⩸⩸1)  {      ⩸⩸⩸⩸      ⩸⩸⩸⩸      if  (⩸⩸2)  {          ⩸⩸⩸⩸      }  else  {          ⩸⩸⩸          ⩸⩸⩸⩸⩸⩸          ⩸⩸          if  (⩸⩸⩸3)  {              ⩸⩸          }  else  {              ⩸⩸                    ⩸⩸⩸⩸⩸⩸          }      }   }  else  {      ⩸⩸⩸   } 1: true 1: true, 2: true 1: true, 2: false 1: true, 2: false, 3: true 1: true, 2: false, 3: false

Slide 25

Slide 25 text

if  (⩸⩸⩸⩸⩸1)  {      ⩸⩸⩸⩸      ⩸⩸⩸⩸      if  (⩸⩸2)  {          ⩸⩸⩸⩸      }  else  {          ⩸⩸⩸          ⩸⩸⩸⩸⩸⩸          ⩸⩸          if  (⩸⩸⩸3)  {              ⩸⩸          }  else  {              ⩸⩸                    ⩸⩸⩸⩸⩸⩸          }      }   }  else  {      ⩸⩸⩸   } 1: true 1: true, 2: true 1: true, 2: false 1: true, 2: false, 3: true 1: true, 2: false, 3: false 1: false, 2 & 3 don’t matter

Slide 26

Slide 26 text

if  (⩸⩸⩸⩸⩸1)  {      ⩸⩸⩸⩸      ⩸⩸⩸⩸      if  (⩸⩸2)  {          ⩸⩸⩸⩸      }  else  {          ⩸⩸⩸          ⩸⩸⩸⩸⩸⩸          ⩸⩸          if  (⩸⩸⩸3)  {              ⩸⩸          }  else  {              ⩸⩸                    ⩸⩸⩸⩸⩸⩸          }      }   }  else  {      ⩸⩸⩸   } 1: true 1: true, 2: true 1: true, 2: false 1: true, 2: false, 3: true 1: true, 2: false, 3: false 1: false, 2 & 3 don’t matter We have to context-switch

Slide 27

Slide 27 text

if  (⩸⩸⩸⩸⩸1)  {      ⩸⩸⩸⩸      ⩸⩸⩸⩸      if  (⩸⩸2)  {          ⩸⩸⩸⩸          ⩸⩸⩸⩸⩸⩸          ⩸⩸          if  (⩸⩸⩸3)  {              ⩸⩸              if  (⩸⩸⩸4)  {                  ⩸⩸                        ⩸⩸⩸⩸⩸⩸              }              ⩸⩸              ⩸⩸⩸⩸⩸⩸⩸⩸          }      }   }

Slide 28

Slide 28 text

if  (⩸⩸⩸⩸⩸1)  {      ⩸⩸⩸⩸      ⩸⩸⩸⩸      if  (⩸⩸2)  {          ⩸⩸⩸⩸          ⩸⩸⩸⩸⩸⩸          ⩸⩸          if  (⩸⩸⩸3)  {              ⩸⩸              if  (⩸⩸⩸4)  {                  ⩸⩸                        ⩸⩸⩸⩸⩸⩸              }              ⩸⩸              ⩸⩸⩸⩸⩸⩸⩸⩸          }      }   } 1: true

Slide 29

Slide 29 text

if  (⩸⩸⩸⩸⩸1)  {      ⩸⩸⩸⩸      ⩸⩸⩸⩸      if  (⩸⩸2)  {          ⩸⩸⩸⩸          ⩸⩸⩸⩸⩸⩸          ⩸⩸          if  (⩸⩸⩸3)  {              ⩸⩸              if  (⩸⩸⩸4)  {                  ⩸⩸                        ⩸⩸⩸⩸⩸⩸              }              ⩸⩸              ⩸⩸⩸⩸⩸⩸⩸⩸          }      }   } 1: true 1 & 2: TRUE

Slide 30

Slide 30 text

if  (⩸⩸⩸⩸⩸1)  {      ⩸⩸⩸⩸      ⩸⩸⩸⩸      if  (⩸⩸2)  {          ⩸⩸⩸⩸          ⩸⩸⩸⩸⩸⩸          ⩸⩸          if  (⩸⩸⩸3)  {              ⩸⩸              if  (⩸⩸⩸4)  {                  ⩸⩸                        ⩸⩸⩸⩸⩸⩸              }              ⩸⩸              ⩸⩸⩸⩸⩸⩸⩸⩸          }      }   } 1: true 1 & 2: TRUE 1 & 2 & 3: TRUE

Slide 31

Slide 31 text

if  (⩸⩸⩸⩸⩸1)  {      ⩸⩸⩸⩸      ⩸⩸⩸⩸      if  (⩸⩸2)  {          ⩸⩸⩸⩸          ⩸⩸⩸⩸⩸⩸          ⩸⩸          if  (⩸⩸⩸3)  {              ⩸⩸              if  (⩸⩸⩸4)  {                  ⩸⩸                        ⩸⩸⩸⩸⩸⩸              }              ⩸⩸              ⩸⩸⩸⩸⩸⩸⩸⩸          }      }   } 1: true 1 & 2: TRUE 1 & 2 & 3: TRUE 1 & 2 & 3 & 4: true

Slide 32

Slide 32 text

if  (⩸⩸⩸⩸⩸1)  {      ⩸⩸⩸⩸      ⩸⩸⩸⩸      if  (⩸⩸2)  {          ⩸⩸⩸⩸          ⩸⩸⩸⩸⩸⩸          ⩸⩸          if  (⩸⩸⩸3)  {              ⩸⩸              if  (⩸⩸⩸4)  {                  ⩸⩸                        ⩸⩸⩸⩸⩸⩸              }              ⩸⩸              ⩸⩸⩸⩸⩸⩸⩸⩸          }      }   } 1: true 1 & 2: TRUE 1 & 2 & 3: TRUE 1 & 2 & 3 & 4: true No switches, just adding :-)

Slide 33

Slide 33 text

C H A N G E I S B A D

Slide 34

Slide 34 text

B U I L D I N G I S G O O D

Slide 35

Slide 35 text

W H Y ?

Slide 36

Slide 36 text

we use complex logic: • More when we talk to computers • less when we talk to people

Slide 37

Slide 37 text

P E O P L E A R E N OT G R E AT AT LO G I C

Slide 38

Slide 38 text

No content

Slide 39

Slide 39 text

P E O P L E A R E N OT G R E AT AT F O L LO W I N G S TAT E

Slide 40

Slide 40 text

Pepole are graet at reizncinogg patetrns, but teirrlbe at foonwillg loigc.

Slide 41

Slide 41 text

FA C E S P E O P L E A R E G O O D AT

Slide 42

Slide 42 text

No content

Slide 43

Slide 43 text

No content

Slide 44

Slide 44 text

S O U N D S P E O P L E A R E G O O D AT

Slide 45

Slide 45 text

No content

Slide 46

Slide 46 text

https://www.flickr.com/photos/fdecomite/446394032/in/photostream/

Slide 47

Slide 47 text

M O R E PAT T E R N S L E S S “ E L S E ”

Slide 48

Slide 48 text

N OT N E C E S S A R I LY “ D E S I G N PAT T E R N S "

Slide 49

Slide 49 text

0 . E M P H A S I Z E E S S E N T I A L C O D E

Slide 50

Slide 50 text

valid  =  validator(data)   if  (valid)  {          ⩸⩸⩸⩸⩸⩸          ⩸⩸⩸⩸⩸          ⩸⩸⩸          ⩸⩸⩸⩸⩸⩸   }  else  {      return  null;   }   ⩸⩸⩸⩸⩸⩸   return  data;

Slide 51

Slide 51 text

valid  =  validator(data)   if  (valid)  {          ⩸⩸⩸⩸⩸⩸          ⩸⩸⩸⩸⩸          ⩸⩸⩸          ⩸⩸⩸⩸⩸⩸   }  else  {      return  null;   }   ⩸⩸⩸⩸⩸⩸   return  data; essential code

Slide 52

Slide 52 text

valid  =  validator(data)   if  (!valid)  {      return  null;   }   ⩸⩸⩸⩸⩸⩸   ⩸⩸⩸⩸⩸   ⩸⩸⩸   ⩸⩸⩸⩸⩸⩸   ⩸⩸⩸⩸⩸⩸   return  data; essential code

Slide 53

Slide 53 text

1 . P O LYM O R P H I S M

Slide 54

Slide 54 text

G R E E K MY T H O LO GY ?

Slide 55

Slide 55 text

fieldAsHtml:  function(field)  {      if  ('text'  ===  field.type)          return  ;   else  if  ('number'  ===  field.type)          return  ;      else  if  ('textarea'  ===  field.type)          return        else          throw  new  IMissYou(type,  field)   }

Slide 56

Slide 56 text

fieldAsHtml:  function(field)  {      if  ('text'  ===  field.type)          return  ;   else  if  ('number'  ===  field.type)          return  ;      else  if  ('textarea'  ===  field.type)          return        else          throw  new  IMissYou(type,  field)   } fieldAsHtml:  function(field)  {      renderer  =  renderers[field.type]  ||  throw…      return  renderer(field)   }

Slide 57

Slide 57 text

Design pattern: strategy™

Slide 58

Slide 58 text

refactoring: Replace Conditional with Polymorphism™

Slide 59

Slide 59 text

P E O P L E ❤️ PAT T E R N S

Slide 60

Slide 60 text

No content

Slide 61

Slide 61 text

No content

Slide 62

Slide 62 text

if  ('text'  ===  field.type)      return  ⩸⩸⩸⩸⩸;   else  if  ('textarea'  ===  field.type)      return  ⩸⩸⩸⩸⩸;   else  if  ('number'  ===  field.type)      return  ⩸⩸⩸⩸⩸;   else  if  ('airplane  on  wheels'  ===  field.type)      return  ⩸⩸⩸⩸⩸;   else  if  ('scooter  with  squirrel'  ===  field.type)      return  ⩸⩸⩸⩸⩸;   else  if  ('name'  ===  field.type  &&  name.length  >  5      return  ⩸⩸⩸⩸⩸;   else  if  ('name'  ===  field.type  &&  name.length  <  5      return  ⩸⩸⩸⩸⩸;   else  if  ('textarea  on  JavaScript'  ===  field.type)      return  ⩸⩸⩸⩸⩸;   else  if  ('textarea  raised  with  love'  ===  field.type)      return  ⩸⩸⩸⩸⩸;   else      return  ⩸⩸⩸⩸⩸;

Slide 63

Slide 63 text

if  ('text'  ===  field.type)      return  ⩸⩸⩸⩸⩸;   else  if  ('textarea'  ===  field.type)      return  ⩸⩸⩸⩸⩸;   else  if  ('number'  ===  field.type)      return  ⩸⩸⩸⩸⩸;   else  if  ('airplane  on  wheels'  ===  field.type)      return  ⩸⩸⩸⩸⩸;   else  if  ('scooter  with  squirrel'  ===  field.type)      return  ⩸⩸⩸⩸⩸;   else  if  ('name'  ===  field.type  &&  name.length  >  5)      return  ⩸⩸⩸⩸⩸;   else  if  ('name'  ===  field.type  &&  name.length  <  5)      return  ⩸⩸⩸⩸⩸;   else  if  ('textarea  on  JavaScript'  ===  field.type)      return  ⩸⩸⩸⩸⩸;   else  if  ('textarea  raised  with  love'  ===  field.type)      return  ⩸⩸⩸⩸⩸;   else      return  ⩸⩸⩸⩸⩸;

Slide 64

Slide 64 text

2 . P U T M O R E F O C U S O N A C T I O N

Slide 65

Slide 65 text

if  (spring)  {      if  (weekday)  {          school();      }  elseif  (saturday)  {          if  (raining)              tv();          else              football();      }  else  {          homework();      }   }  else  if  (winter)  {      hibernate();   }

Slide 66

Slide 66 text

if  (spring)  {      if  (weekday)  {          school();      }  elseif  (saturday)  {          if  (raining)              tv();          else              football();      }  else  {          homework();      }   }  else  if  (winter)  {      hibernate();   } if  (spring  &&  weekday)      school();   if  (spring  &&  saturday  &&  !raining)      football();   if  (spring  &&  saturday  &&  raining)      tv();   if  (spring  &&  sunday)      homework();   if  (winter)      hibernate();

Slide 67

Slide 67 text

if  (spring)  {      if  (weekday)  {          school();      }  elseif  (saturday)  {          if  (raining)              tv();          else              football();      }  else  {          homework();      }   }  else  if  (winter)  {      hibernate();   } if  (spring  &&  weekday)      school();   if  (spring  &&  saturday  &&  !raining)      football();   if  (spring  &&  saturday  &&  raining)      tv();   if  (spring  &&  sunday)      homework();   if  (winter)      hibernate();

Slide 68

Slide 68 text

3 . N O E S C A P E

Slide 69

Slide 69 text

E X T R A C T!

Slide 70

Slide 70 text

if  (⩸⩸⩸⩸⩸1)  {      ⩸⩸⩸⩸      ⩸⩸⩸⩸      if  (⩸⩸2)  {          ⩸⩸⩸⩸      }  else  {          ⩸⩸⩸          ⩸⩸⩸⩸⩸⩸          ⩸⩸          if  (⩸⩸⩸3)  {              ⩸⩸          }  else  {              ⩸⩸                    ⩸⩸⩸⩸⩸⩸          }      }   }  else  {      ⩸⩸⩸   }

Slide 71

Slide 71 text

if  (⩸⩸⩸⩸⩸1)  {      ⩸⩸⩸⩸      ⩸⩸⩸⩸      if  (⩸⩸2)  {          ⩸⩸⩸⩸      }  else  {          ⩸⩸⩸          ⩸⩸⩸⩸⩸⩸          ⩸⩸          if  (⩸⩸⩸3)  {              ⩸⩸          }  else  {              ⩸⩸                    ⩸⩸⩸⩸⩸⩸          }      }   }  else  {      ⩸⩸⩸   } if  (⩸⩸⩸⩸⩸1)  {      ⦾(⩸,  ⩸⩸⩸)   }  else  {      ⩸⩸⩸   }   function  ⦾(⩸,  ⩸⩸⩸)  {      ⪍  ⪍  ⪍      ⪍      ⪍  ⪍  ⪍  ⪍   }

Slide 72

Slide 72 text

if  (⩸⩸⩸⩸⩸1)  {      ⩸⩸⩸⩸      ⩸⩸⩸⩸      if  (⩸⩸2)  {          ⩸⩸⩸⩸      }  else  {          ⩸⩸⩸          ⩸⩸⩸⩸⩸⩸          ⩸⩸          if  (⩸⩸⩸3)  {              ⩸⩸          }  else  {              ⩸⩸                    ⩸⩸⩸⩸⩸⩸          }      }   }  else  {      ⩸⩸⩸   } var  ⪍  =  ⩸⩸⩸⩸⩸1;   if  (⪍)  {      ⦾(⩸,  ⩸⩸⩸)   }  else  {      ⩸⩸⩸   }

Slide 73

Slide 73 text

I N D I R E C T I O N ! = A B S T R A C T I O N

Slide 74

Slide 74 text

P RO G R A M M I N G + U S A B I L I T Y = ❤️

Slide 75

Slide 75 text

No content

Slide 76

Slide 76 text

P E O P L E > CO M P U T E R S

Slide 77

Slide 77 text

T H A N KS ! @ N I KO L AY B H T T P : // E X T R A P O L AT E . M E /