Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Programming by Hyperbole
Search
Einar W. Høst
March 13, 2013
Programming
0
99
Programming by Hyperbole
Lightning talk from the Booster 2013 conference.
Einar W. Høst
March 13, 2013
Tweet
Share
More Decks by Einar W. Høst
See All by Einar W. Høst
No Silver Bullet (Fred Brooks)
einarwh
0
82
einarwh-death-of-a-craftsman-boosterconf-2019_original.pdf
einarwh
1
130
Technical debt isn't technical
einarwh
5
720
Other Decks in Programming
See All in Programming
Pinia Colada が実現するスマートな非同期処理
naokihaba
4
220
Jakarta EE meets AI
ivargrimstad
0
170
Nurturing OpenJDK distribution: Eclipse Temurin Success History and plan
ivargrimstad
0
910
見せてあげますよ、「本物のLaravel批判」ってやつを。
77web
7
7.7k
PHP でアセンブリ言語のように書く技術
memory1994
PRO
1
170
AI時代におけるSRE、 あるいはエンジニアの生存戦略
pyama86
6
1.1k
ピラミッド、アイスクリームコーン、SMURF: 自動テストの最適バランスを求めて / Pyramid Ice-Cream-Cone and SMURF
twada
PRO
10
1.3k
CSC509 Lecture 09
javiergs
PRO
0
140
cmp.Or に感動した
otakakot
3
170
CSC509 Lecture 12
javiergs
PRO
0
160
Compose 1.7のTextFieldはPOBox Plusで日本語変換できない
tomoya0x00
0
190
What’s New in Compose Multiplatform - A Live Tour (droidcon London 2024)
zsmb
1
470
Featured
See All Featured
StorybookのUI Testing Handbookを読んだ
zakiyama
27
5.3k
Mobile First: as difficult as doing things right
swwweet
222
8.9k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
33
1.9k
Six Lessons from altMBA
skipperchong
27
3.5k
The World Runs on Bad Software
bkeepers
PRO
65
11k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.1k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
26
2.1k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.3k
The Language of Interfaces
destraynor
154
24k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
131
33k
Adopting Sorbet at Scale
ufuk
73
9.1k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
25
1.8k
Transcript
Programming by Hyperbole Einar W. Høst
Take a small task from work Take a small
but real problem you encounter at work.
Bring it back home where no-‐one can ques@on
your ra@onale.
Apply hyperbole to exaggerate, distort &
bend it.
(Blog about it and put it on github.)
What is hyperbole?
Normal Normal HYPERBOLE NORMAL
Normal You see a string in your program
and you think... NORMAL
Normal “Yup, that’s a string.” NORMAL
“Hey, that’s a string.” HYPERBOLE You see a
string in your program and you think...
“Hey, that’s a string.” HYPERBOLE “I could put
a programming language in there.”
Why?
None
Understanding is limited
Understanding is par@al
Understanding is full of myths and half-‐truths
Understanding is misunderstanding
Understanding is plain wrong
Understanding is not improved at work
Hyperbole helps
Hyperbole by Example
5 + 2 * 3 Actual Business Case
In my HTML form, how can I validate that a DateTime value is between two other DateTime values?
5 + 2 * 3 ASP.NET MVC Model Valida@on
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; } }
5 + 2 * 3 Data Annota@on Validator Adributes
> Required > Range > RegularExpression > MinLength > MaxLength > ...
5 + 2 * 3 Data Annota@on Validator Adributes
> Required > Range > RegularExpression > MinLength > MaxLength > ...
5 + 2 * 3 Data Annota@on Validator Adributes
> Required > Range > RegularExpression > MinLength > MaxLength > ...
5 + 2 * 3 Data Annota@on Validator Adributes
> Remote > Custom
5 + 2 * 3 Data Annota@on Validator Adributes
> Remote > Custom
5 + 2 * 3 Actual Business Solu@on
Custom valida@on to solve a very specific problem.
5 + 2 * 3 Hyperbolic Developer Ques@on
Is there a generic solu@on?
5 + 2 * 3 Hyperbolic Developer Ques@on
What would be the ul@mate approach?
5 + 2 * 3 Hyperbolic Developer Ques@on
Can this be solved once and for all?
5 + 2 * 3 Hyperbolic Developer Ques@on
What is the final word on valida@on?
$ $ Developer Constraint At Work Business
value Time spent
$ $ Developer Constraint At Home
5 + 2 * 3 Custom Valida@on Adribute
[ Custom(........) ]
5 + 2 * 3 Custom Valida@on Adribute
[ Custom(........) ] Severely limited
5 + 2 * 3 Custom Valida@on Adribute
[ Custom(“foo”) ] ...but strings are OK
5 + 2 * 3 Custom Valida@on Adribute
[ Custom(“foo”) ] ...strings are OK?
5 + 2 * 3 Custom Valida@on Adribute
[ Custom(“foo”) ] I could put a programming language in there!
5 + 2 * 3 My Hyperbolic Idea
Create a rule DSL for expressing arbitrary constraints on property values in a LISP-‐like syntax.
5 + 2 * 3 Why?
5 + 2 * 3 Why? Do. Or
do not. There is no why.
5 + 2 * 3 Why? If it
fits, I sits
5 + 2 * 3 Why? > Custom
Valida@on > S-‐expressions > Expression Trees > Func@onal JavaScript > Code Genera@on > Code Interpreta@on Learning opportunity
(+ 5 (* 2 3)) [ Mkay(“(and (> A)
(< B))”) ] Introducing Mkay One valida@on adribute to rule them all
(+ 5 (* 2 3)) Mkay expressions >
Constants > Property access > Logical operators > Comparison operators > Simple func@ons
(+ 5 (* 2 3)) Example #1 [
Mkay(“>= (max A B)”) ]
(+ 5 (* 2 3)) Example #2 [
Mkay(“== (len .) 5”) ]
(+ 5 (* 2 3)) Example #3 [
Mkay(“and (> “31.01.2006”) (<= (now))”) ]
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
(+ 5 (* 2 3)) Mkay Rule DSL
(> . (+ A B C))
(+ 5 (* 2 3)) Abstract Syntax Tree
symbol > symbol + symbol . nil symbol A symbol B symbol C nil (> . (+ A B C))
(+ 5 (* 2 3)) Expression Tree Member
. Member B Member A Member C Binary + Binary > Binary + (> . (+ A B C))
(+ 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))
(+ 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
5 + 2 * 3 Demo
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; } }
Demo
BLOG hdp://einarwh.wordpress.com CODE hdp://bitbucket.org/einarwh/mkay DOWNLOAD
hdp://nuget.org/packages/mkay
5 + 2 * 3 HYPERBOLIC HYPERBOLE
5 + 2 * 3 eval
None
“Hey, that’s a string.” HYPERBOLE You see a
string in your program and you think...
“Hey, that’s a string.” HYPERBOLE “I could put
a programming language in there.”
GO ONE LOUDER