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
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
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
360
Wide Event Analytics (LISA19)
igorw
4
940
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
330
Other Decks in Programming
See All in Programming
スマートグラスで並列バイブコーディング
hyshu
0
280
【SRE NEXT 2026 Lunch Session】一人目専任SREの立ち上げを加速する ― AIと進めたオンボーディングで2分を0.04秒にした話
pkshadeck
PRO
0
2.1k
エンジニアと一緒にテストコードの設計と実装を改善した話
mototakatsu
0
260
20260623_Loop Engineeringで自分の分身の問い合わせBotを作る
ryugen04
0
190
吝嗇家のためのAI活用 / AI development for miser - ChatGPT + Issue Driven Development
tooppoo
0
180
The Bowling Game- From Imperative to Functional Programming - Part 1
philipschwarz
PRO
0
300
トークンをケチるな、設計しろ:GitHub Copilotを賢く使うコンテキスト戦略
ochtum
0
300
Hunting Vulnerabilities in Symfony with LLMs
vinceamstoutz
0
580
キャリア迷子上等 ─ "ない道"は自分で作ればいい
16bitidol
3
2.8k
Semantic Version 単位で戦略を柔軟に変えて、パッケージアップデートを自動化する
daitasu
1
350
過去最大のMCPアップデート! 2026-07-28 RC版の謎に迫る
licux
6
460
SREの積み重ねがAI駆動開発のガードレールになった ― 7つの実践/SRE Guardrails The 7
tomoyakitaura
8
3.6k
Featured
See All Featured
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
1
170
Marketing Yourself as an Engineer | Alaka | Gurzu
gurzu
0
260
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
280
The Curse of the Amulet
leimatthew05
2
13k
We Are The Robots
honzajavorek
0
270
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
0
440
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
55k
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
340
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
3
180
Google's AI Overviews - The New Search
badams
0
1.1k
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
1
370
Leading Effective Engineering Teams in the AI Era
addyosmani
9
2.1k
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