Slide 1

Slide 1 text

Programming  by  Hyperbole   Einar  W.  Høst  

Slide 2

Slide 2 text

Take  a  small  task  from  work   Take  a  small  but   real  problem  you   encounter  at  work.  

Slide 3

Slide 3 text

Bring  it  back  home   where  no-­‐one  can   ques@on  your   ra@onale.  

Slide 4

Slide 4 text

Apply  hyperbole     to  exaggerate,     distort  &  bend  it.  

Slide 5

Slide 5 text

(Blog  about  it  and   put  it  on  github.)  

Slide 6

Slide 6 text

What  is  hyperbole?  

Slide 7

Slide 7 text

Normal   Normal   HYPERBOLE   NORMAL  

Slide 8

Slide 8 text

Normal   You  see  a  string  in  your   program  and  you  think...   NORMAL  

Slide 9

Slide 9 text

Normal   “Yup,  that’s  a  string.”   NORMAL  

Slide 10

Slide 10 text

“Hey,  that’s  a  string.”   HYPERBOLE   You  see  a  string  in  your   program  and  you  think...  

Slide 11

Slide 11 text

“Hey,  that’s  a  string.”   HYPERBOLE   “I  could  put  a  programming   language  in  there.”  

Slide 12

Slide 12 text

Why?  

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

Understanding  is   limited  

Slide 15

Slide 15 text

Understanding  is   par@al  

Slide 16

Slide 16 text

Understanding  is   full  of  myths  and  half-­‐truths  

Slide 17

Slide 17 text

Understanding  is   misunderstanding  

Slide 18

Slide 18 text

Understanding  is   plain  wrong  

Slide 19

Slide 19 text

Understanding  is   not  improved  at  work  

Slide 20

Slide 20 text

Hyperbole   helps  

Slide 21

Slide 21 text

Hyperbole  by  Example  

Slide 22

Slide 22 text

5  +  2  *  3   Actual  Business  Case   In  my  HTML  form,  how  can  I  validate     that  a  DateTime  value  is  between     two  other  DateTime  values?  

Slide 23

Slide 23 text

5  +  2  *  3   ASP.NET  MVC  Model  Valida@on  

Slide 24

Slide 24 text

5  +  2  *  3   ASP.NET  MVC  Model  Valida@on   public  class  User   {          [  Required  ]          public  string  UserName  {  get;  set;  }          [  Required  ]          [  MinLength(12)  ]          public  string  Password  {  get;  set;  }   }  

Slide 25

Slide 25 text

5  +  2  *  3   Data  Annota@on  Validator  Adributes   >  Required   >  Range   >  RegularExpression   >  MinLength   >  MaxLength   >  ...  

Slide 26

Slide 26 text

5  +  2  *  3   Data  Annota@on  Validator  Adributes   >  Required   >  Range   >  RegularExpression   >  MinLength   >  MaxLength   >  ...  

Slide 27

Slide 27 text

5  +  2  *  3   Data  Annota@on  Validator  Adributes   >  Required   >  Range   >  RegularExpression   >  MinLength   >  MaxLength   >  ...  

Slide 28

Slide 28 text

5  +  2  *  3   Data  Annota@on  Validator  Adributes   >  Remote   >  Custom  

Slide 29

Slide 29 text

5  +  2  *  3   Data  Annota@on  Validator  Adributes   >  Remote   >  Custom  

Slide 30

Slide 30 text

5  +  2  *  3   Actual  Business  Solu@on   Custom  valida@on  to  solve     a  very  specific  problem.  

Slide 31

Slide 31 text

5  +  2  *  3   Hyperbolic  Developer  Ques@on   Is  there  a  generic  solu@on?  

Slide 32

Slide 32 text

5  +  2  *  3   Hyperbolic  Developer  Ques@on   What  would  be  the  ul@mate  approach?  

Slide 33

Slide 33 text

5  +  2  *  3   Hyperbolic  Developer  Ques@on   Can  this  be  solved  once  and  for  all?  

Slide 34

Slide 34 text

5  +  2  *  3   Hyperbolic  Developer  Ques@on   What  is  the  final  word  on  valida@on?  

Slide 35

Slide 35 text

$   $   Developer  Constraint  At  Work   Business  value   Time  spent  

Slide 36

Slide 36 text

$   $   Developer  Constraint  At  Home  

Slide 37

Slide 37 text

5  +  2  *  3   Custom  Valida@on  Adribute   [  Custom(........)  ]  

Slide 38

Slide 38 text

5  +  2  *  3   Custom  Valida@on  Adribute   [  Custom(........)  ]   Severely  limited  

Slide 39

Slide 39 text

5  +  2  *  3   Custom  Valida@on  Adribute   [  Custom(“foo”)  ]   ...but  strings  are  OK  

Slide 40

Slide 40 text

5  +  2  *  3   Custom  Valida@on  Adribute   [  Custom(“foo”)  ]   ...strings  are  OK?  

Slide 41

Slide 41 text

5  +  2  *  3   Custom  Valida@on  Adribute   [  Custom(“foo”)  ]   I  could  put  a     programming     language  in  there!  

Slide 42

Slide 42 text

5  +  2  *  3   My  Hyperbolic  Idea   Create  a  rule  DSL  for  expressing   arbitrary  constraints  on  property     values  in  a  LISP-­‐like  syntax.  

Slide 43

Slide 43 text

5  +  2  *  3   Why?  

Slide 44

Slide 44 text

5  +  2  *  3   Why?   Do.  Or  do  not.   There  is  no  why.  

Slide 45

Slide 45 text

5  +  2  *  3   Why?   If  it  fits,  I  sits  

Slide 46

Slide 46 text

5  +  2  *  3   Why?   >  Custom  Valida@on   >  S-­‐expressions   >  Expression  Trees   >  Func@onal  JavaScript   >  Code  Genera@on   >  Code  Interpreta@on   Learning  opportunity  

Slide 47

Slide 47 text

(+  5  (*  2  3))   [  Mkay(“(and  (>  A)  (<  B))”)  ]   Introducing  Mkay   One  valida@on  adribute  to  rule  them  all  

Slide 48

Slide 48 text

(+  5  (*  2  3))   Mkay  expressions   >  Constants   >  Property  access   >  Logical  operators   >  Comparison  operators   >  Simple  func@ons  

Slide 49

Slide 49 text

(+  5  (*  2  3))   Example  #1   [  Mkay(“>=  (max  A  B)”)  ]  

Slide 50

Slide 50 text

(+  5  (*  2  3))   Example  #2   [  Mkay(“==  (len  .)  5”)  ]  

Slide 51

Slide 51 text

(+  5  (*  2  3))   Example  #3   [  Mkay(“and  (>  “31.01.2006”)  (<=  (now))”)  ]  

Slide 52

Slide 52 text

Rule  AST   Cons  Cells   .NET     Expression  Trees   JavaScript   JSON   Server-­‐side  valida@on   Client-­‐side  valida@on   Rule  DSL   String   .NET     Func@on   JavaScript   Func@on  

Slide 53

Slide 53 text

(+  5  (*  2  3))   Mkay  Rule  DSL   (>  .  (+  A  B  C))  

Slide 54

Slide 54 text

(+  5  (*  2  3))   Abstract  Syntax  Tree   symbol   >   symbol   +   symbol   .   nil   symbol   A   symbol   B   symbol   C   nil   (>  .  (+  A  B  C))  

Slide 55

Slide 55 text

(+  5  (*  2  3))   Expression  Tree   Member   .   Member   B   Member   A   Member   C   Binary   +   Binary   >   Binary   +   (>  .  (+  A  B  C))  

Slide 56

Slide 56 text

(+  5  (*  2  3))   JSON   {      "type":  "call",      "value":  ">",      "operands":  [          {              "type":  "property",              "value":  "X"          },          {              "type":  "call",              "value":  "+",              "operands":  [                  {                      "type":  "property",                      "value":  "A"                  },                  {                      "type":  "property",                      "value":  "B"                  },                  {                      "type":  "property",                      "value":  "C"                  }              ]          }      ]   }   (>  .  (+  A  B  C))  

Slide 57

Slide 57 text

(+  5  (*  2  3))   Composed  Valida@on  Func@on   function()  {      return  greater-­‐than-­‐function      (          read-­‐property-­‐function("."),          plus-­‐function(              plus-­‐function(                  plus-­‐function(                      0,                        read-­‐property-­‐function("C")),                  read-­‐property-­‐function("B")),              read-­‐property-­‐function("A"))      );   }   Pseudo-­‐JavaScript  

Slide 58

Slide 58 text

5  +  2  *  3   Demo  

Slide 59

Slide 59 text

5  +  2  *  3   Demo   public  class  Person     {            [  Mkay("(<  (len  .)  5)",  ErrorMessage  =  "That's  too  long,  my  friend.")  ]            public  string  Name  {  get;  set;  }            [  Mkay("(>=  .  \"31.01.1900\")")  ]            public  DateTime  BirthDate  {  get;  set;  }            [  Mkay("(<=  .  (now))")  ]            public  DateTime  DeathDate  {  get;  set;  }            [  Mkay("(and  (>=  .  BirthDate)  (<=  .  DeathDate))")  ]            public  DateTime  LastSeen  {  get;  set;  }     }  

Slide 60

Slide 60 text

Demo  

Slide 61

Slide 61 text

BLOG   hdp://einarwh.wordpress.com   CODE   hdp://bitbucket.org/einarwh/mkay   DOWNLOAD   hdp://nuget.org/packages/mkay  

Slide 62

Slide 62 text

5  +  2  *  3   HYPERBOLIC   HYPERBOLE  

Slide 63

Slide 63 text

5  +  2  *  3   eval  

Slide 64

Slide 64 text

No content

Slide 65

Slide 65 text

“Hey,  that’s  a  string.”   HYPERBOLE   You  see  a  string  in  your   program  and  you  think...  

Slide 66

Slide 66 text

“Hey,  that’s  a  string.”   HYPERBOLE   “I  could  put  a  programming   language  in  there.”  

Slide 67

Slide 67 text

GO  ONE  LOUDER