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
Dysfunctional Programming (phpnw13)
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Igor Wiedler
October 05, 2013
Programming
1k
3
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Dysfunctional Programming (phpnw13)
Igor Wiedler
October 05, 2013
More Decks by Igor Wiedler
See All by Igor Wiedler
Redis Bedtime Stories
igorw
1
370
Wide Event Analytics (LISA19)
igorw
4
950
a day in the life of a request
igorw
0
170
production: an owner's manual
igorw
0
200
The Power of 2
igorw
0
340
LISP 1.5 Programmer's Manual: A Dramatic Reading
igorw
0
490
The Moral Character of Software
igorw
1
320
interdisciplinary computing (domcode)
igorw
0
320
miniKanren (clojure berlin)
igorw
1
340
Other Decks in Programming
See All in Programming
AI時代に設計が 最大の生産性レバーになる 意図駆動開発とデータを消さない設計|Don't Delete Your Data or Your Intent — Design as the Deepest Lever in the AI Era
tomohisa
1
510
torikago - Ruby::Boxで照らすモジュラモノリスの実行境界
se4weed
1
320
属人化した知識を、 AIが辿れる地図にする
pkshadeck
PRO
1
130
PHP に部分適用が来るぞ!……ところで何それ?おいしいの? #phpcon / phpcon-2026
shogogg
0
510
PostgreSQL 18で考えるUUID主キー
kazuhiro1982
0
450
jsmini JavaScript Engine を作ってみた話
yosuke_furukawa
PRO
0
290
自動化したのに回らないテスト運用の壁ーAI時代の品質責任と生産性
mfunaki
0
120
作るコストが小さくなった時代 幸せに働くために改めて考えたいこと 〜エンジニアとして価値を出し続けるために注視している二分野〜
yuppeeng
0
180
Apache Hive: Toward a Cloud Native Lakehouse
okumin
0
170
20260722_microCMSで考える、AI時代のコンテンツ運用設計
yosh1
0
260
ソフトウェア設計に溶けるインフラ ― AWS CDK のインフラ認識論
konokenj
3
740
AI時代のPHPer生存戦略 ~「言語、もうなんでもよくない?」に本気で向き合う~
vivion
0
220
Featured
See All Featured
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
56
3.4k
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
330
Stop Working from a Prison Cell
hatefulcrawdad
274
21k
Typedesign – Prime Four
hannesfritz
42
3.1k
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
1
1.5k
KATA
mclloyd
PRO
35
15k
The Mindset for Success: Future Career Progression
greggifford
PRO
0
430
How to build a perfect <img>
jonoalderson
1
5.8k
Making Projects Easy
brettharned
120
6.7k
Statistics for Hackers
jakevdp
799
230k
Fashionably flexible responsive web design (full day workshop)
malarkey
408
67k
How to train your dragon (web standard)
notwaldorf
97
6.7k
Transcript
Dysfunctional Programming
@igorwesome
None
None
None
Immuteability: The property of functional programmers that prevents them from
shutting up about pure functional programming. – Reg Braithwaite @raganwald
dys·func·tion·al
php λ
Paradigms
procedural Object- Oriented functional logic
Imperative Declarative
Structure Time & State
Structure
None
‘sup?
None
it’s not about the money
• Message passing • Interfaces • Composition • (Not inheritance)
Actor model: Asynchronous
None
None
f g h
tools and materials
• Value semantics • Higher-order functions • Lazy evaluation
The Garbage Overfloweth
$numberCollection = new NumberCollection(); $numberParser = new SimpleNumberStringParser(); $firstParsedNumber =
$numberParser->parse('1'); $firstNumber = new SimpleNumber($firstParsedNumber); $firstNumberProxy = new CollectionItemNumberProxy($firstNumber); $numberCollection->add($firstNumberProxy); $secondParsedNumber = $numberParser->parse('1'); $secondNumber = new SimpleNumber($secondParsedNumber); $secondNumberProxy = new CollectionItemNumberProxy($secondNumber); $numberCollection->add($secondNumberProxy); $addition = new AdditionOperator('SimplePHPEasyPlus\Number\SimpleNumber'); $operation = new ArithmeticOperation($addition); $engine = new Engine($operation); $calcul = new Calcul($engine, $numberCollection); $runner = new CalculRunner(); $runner->run($calcul); $result = $calcul->getResult(); $numericResult = $result->getValue();
1 + 1
Composition
c a b a b
a b c
Higher-order functions
Dependency Injection
Inversion of control is really just a pretentious way of
saying “Taking an argument”. – Rúnar Óli @runarorama
Taking an argument
g g’
0 1 2 3 4 even? 0 2 4
0 1 2 3 4 #(+ 5 %) 5 7
9 6 8
3 6 7 9 + 0 9 25 3 16
acumulator
Datastructures
Number 42 String "Hello, cruel world." Map {:foo "bar", :baz
"qux"} List [:a :b :c] Set #{"Arthur Dent" "Ford Prefect"}
function is a means of abstraction
data is a means of abstraction
Structure Time & State
Time & State
Place-Oriented Programming
None
None
None
None
identity
new Foo("x") !== new Foo("x")
defensive copy
$users = new UserList(); $users->add(new User("Igor")); notify($users);
while (count($users)) { $user = $users->shift(); notifyUser($user); }
notify(clone $users)
observation
$user->getName()
$user["name"]
Value
Primitives
Value Object
date address money response request
serialization
History
Objects are forgetful
$sophie->setName("Joanna")
2013-09-13 01:01:47 Sophie 2013-09-13 01:02:25 Joanna 2013-09-13 01:05:31 Caroline
$joanna = $sophie->setName("Joanna")
Git
98ca9 34ac2 f30ab master Snapshot A Snapshot B Snapshot C
Epochal Time Model
v1 v2 v3 v4 f f f identity states events
Lazy evaluation
Iterator Generator Stream
a b c d a’ b’ c’ d’ consume
Order of execution becomes implicit
๏ filter ๏ map ๏ reduce
What about I/O?
Filesystem Database Network }is a place
Separate I/O from computation
None
What about testing?
But I heard static methods are untestable and evil
You cannot mock functions
Why do we mock?
Functions are fast
Impure parts are mocked by passing functions
my_beautiful_program(function () { return do_evil_shit(); })
Pure functions are inherently testable
But functions make code look awkward!
strlen(get_name(get_user($data)))
$data |> get_user |> get_name |> strlen
pipeline('get_user', 'get_name', 'strlen')
But PHP does not properly support functions!
use function igorw\edn\parse; $data = parse($edn);
PHP 5.6 will hopefully get function autoloading
Applicability of the functional paradigm
f g h i j k l
A foo foo foo foo B foo foo C foo
foo D foo foo E foo foo
Granularity
None
Queue
๏ Value semantics ๏ Higher-order functions ๏ Lazy evaluation
pure functions
None
Questions? • joind.in/{ 9471, 9472 } • github.com/igorw/edn • github.com/nikic/iter
• @igorwesome
References • The Paradigms of Programming by Robert W. Floyd
• Execution in the Kingdom of Nouns by Steve Yegge • The Value of Values by Rich Hickey • Are we there yet? by Rich Hickey