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
Jakarta Concurrencyによる並行処理プログラミングの始め方 (JJUG CCC 2024 Fall)
tnagao7
1
230
GCCのプラグインを作る / I Made a GCC Plugin
shouth
1
150
レガシーな Android アプリのリアーキテクチャ戦略
oidy
1
170
Sidekiqで実現する 長時間非同期処理の中断と再開 / Pausing and Resuming Long-Running Asynchronous Jobs with Sidekiq
hypermkt
6
2.7k
Kotlin2でdataクラスの copyメソッドを禁止する/Data class copy function to have the same visibility as constructor
eichisanden
1
140
ECS Service Connectのこれまでのアップデートと今後のRoadmapを見てみる
tkikuc
2
210
推し活の ハイトラフィックに立ち向かう Railsとアーキテクチャ - Kaigi on Rails 2024
falcon8823
6
2.2k
hotwire_or_react
harunatsujita
8
4.1k
破壊せよ!データ破壊駆動で考えるドメインモデリング / data-destroy-driven
minodriven
16
4.1k
Vue.js学習の振り返り
hiro_xre
2
130
色々なIaCツールを実際に触って比較してみる
iriikeita
0
270
Nuxtベースの「WXT」でChrome拡張を作成する | Vue Fes 2024 ランチセッション
moshi1121
1
520
Featured
See All Featured
Code Reviewing Like a Champion
maltzj
519
39k
Scaling GitHub
holman
458
140k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
9
680
Adopting Sorbet at Scale
ufuk
73
9k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
131
33k
Being A Developer After 40
akosma
86
590k
Building Better People: How to give real-time feedback that sticks.
wjessup
363
19k
Code Review Best Practice
trishagee
64
17k
Optimizing for Happiness
mojombo
376
69k
RailsConf 2023
tenderlove
29
880
Building Flexible Design Systems
yeseniaperezcruz
327
38k
Art, The Web, and Tiny UX
lynnandtonic
296
20k
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