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
88
einarwh-death-of-a-craftsman-boosterconf-2019_original.pdf
einarwh
1
130
Technical debt isn't technical
einarwh
5
730
Other Decks in Programming
See All in Programming
アクターシステムに頼らずEvent Sourcingする方法について
j5ik2o
4
260
開発者とQAの越境で自動テストが増える開発プロセスを実現する
92thunder
1
180
Webエンジニア主体のモバイルチームの 生産性を高く保つためにやったこと
igreenwood
0
330
ドメインイベント増えすぎ問題
h0r15h0
2
310
なまけものオバケたち -PHP 8.4 に入った新機能の紹介-
tanakahisateru
1
120
RWC 2024 DICOM & ISO/IEC 2022
m_seki
0
210
tidymodelsによるtidyな生存時間解析 / Japan.R2024
dropout009
1
770
PHPUnitしか使ってこなかった 一般PHPerがPestに乗り換えた実録
mashirou1234
0
180
テストコード文化を0から作り、変化し続けた組織
kazatohiei
2
1.5k
rails statsで大解剖 🔍 “B/43流” のRailsの育て方を歴史とともに振り返ります
shoheimitani
2
930
Cloudflare MCP ServerでClaude Desktop からWeb APIを構築
kutakutat
1
550
良いユニットテストを書こう
mototakatsu
7
2.2k
Featured
See All Featured
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
8
1.2k
Site-Speed That Sticks
csswizardry
2
190
How To Stay Up To Date on Web Technology
chriscoyier
789
250k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
38
1.9k
YesSQL, Process and Tooling at Scale
rocio
169
14k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
6.9k
Fontdeck: Realign not Redesign
paulrobertlloyd
82
5.3k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
247
1.3M
Building an army of robots
kneath
302
44k
KATA
mclloyd
29
14k
Art, The Web, and Tiny UX
lynnandtonic
298
20k
How GitHub (no longer) Works
holman
311
140k
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