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
ECS Service Connectのこれまでのアップデートと今後のRoadmapを見てみる
tkikuc
2
250
Kaigi on Rails 2024 〜運営の裏側〜
krpk1900
1
240
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
1
100
macOS でできる リアルタイム動画像処理
biacco42
9
2.4k
Quine, Polyglot, 良いコード
qnighy
4
650
2024/11/8 関西Kaggler会 2024 #3 / Kaggle Kernel で Gemma 2 × vLLM を動かす。
kohecchi
5
930
距離関数を極める! / SESSIONS 2024
gam0022
0
290
CSC509 Lecture 09
javiergs
PRO
0
140
GitHub Actionsのキャッシュと手を挙げることの大切さとそれに必要なこと
satoshi256kbyte
5
430
OnlineTestConf: Test Automation Friend or Foe
maaretp
0
120
Click-free releases & the making of a CLI app
oheyadam
2
120
NSOutlineView何もわからん:( 前編 / I Don't Understand About NSOutlineView :( Pt. 1
usagimaru
0
340
Featured
See All Featured
How to Ace a Technical Interview
jacobian
276
23k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
33
1.9k
Art, The Web, and Tiny UX
lynnandtonic
297
20k
Music & Morning Musume
bryan
46
6.2k
Designing Experiences People Love
moore
138
23k
Building Flexible Design Systems
yeseniaperezcruz
327
38k
Happy Clients
brianwarren
98
6.7k
Agile that works and the tools we love
rasmusluckow
327
21k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
6
430
XXLCSS - How to scale CSS and keep your sanity
sugarenia
246
1.3M
[RailsConf 2023] Rails as a piece of cake
palkan
52
4.9k
A designer walks into a library…
pauljervisheath
204
24k
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