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
96
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
78
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
PHP でアセンブリ言語のように書く技術
memory1994
PRO
1
150
讓數據說話:用 Python、Prometheus 和 Grafana 講故事
eddie
0
350
CSC305 Lecture 13
javiergs
PRO
0
130
Nuxtベースの「WXT」でChrome拡張を作成する | Vue Fes 2024 ランチセッション
moshi1121
1
520
CSC509 Lecture 08
javiergs
PRO
0
110
GCCのプラグインを作る / I Made a GCC Plugin
shouth
1
150
PagerDuty を軸にした On-Call 構築と運用課題の解決 / PagerDuty Japan Community Meetup 4
horimislime
1
110
推し活としてのrails new/oshikatsu_ha_iizo
sakahukamaki
3
1.7k
レガシーな Android アプリのリアーキテクチャ戦略
oidy
1
170
/←このスケジュール表に立ち向かう フロントエンド開発戦略 / A front-end development strategy to tackle a single-slash schedule.
nrslib
1
590
Dev ContainersとGitHub Codespacesの素敵な関係
ymd65536
1
130
PLoP 2024: The evolution of the microservice architecture pattern language
cer
PRO
0
1.6k
Featured
See All Featured
No one is an island. Learnings from fostering a developers community.
thoeni
19
3k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
37
1.8k
Testing 201, or: Great Expectations
jmmastey
38
7k
Ruby is Unlike a Banana
tanoku
96
11k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
92
16k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
328
21k
A better future with KSS
kneath
238
17k
Faster Mobile Websites
deanohume
304
30k
The Cost Of JavaScript in 2023
addyosmani
45
6.6k
Visualization
eitanlees
144
15k
Into the Great Unknown - MozCon
thekraken
31
1.5k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
43
6.6k
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