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
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
190
The Power of 2
igorw
0
340
LISP 1.5 Programmer's Manual: A Dramatic Reading
igorw
0
480
The Moral Character of Software
igorw
1
310
interdisciplinary computing (domcode)
igorw
0
320
miniKanren (clojure berlin)
igorw
1
330
Other Decks in Programming
See All in Programming
Oxlintのカスタムルールの現況
syumai
6
1.1k
例外の正しい扱い方 そのエラー try-catchして大丈夫?
jinwatanabe
0
250
エンジニアと一緒にテストコードの設計と実装を改善した話
mototakatsu
0
180
Go1.27で導入されるジェネリクスメソッドでできること
mackee
0
120
技術記事、AIに書かせるか、自分で書くか? 〜それでも私が自分の手で書く理由〜 / #QiitaConference
jnchito
2
1.4k
エージェンティックRAGにAWSで入門しよう!
har1101
8
1.6k
ローカルLLMでどこまでコードが書けるか -拡張版 / How much code can be written on a local LLM Extended
kishida
11
4.2k
メソッドのジェネリクスでGoの夢は広がるか? / Kyoto.go #65
utgwkk
3
790
ユニットテストの先へ:テスト技法で要求・仕様を整理するJava開発実践 / Beyond_Unit_Testing_Practical_Java_Development_Techniques_for_Organizing_Requirements_and_Specifications
shimashima35
0
410
代数的データ型って何が嬉しいの? #frontend_phpcon_do
kajitack
8
3.7k
The NotImplementedError Problem in Ruby
koic
1
800
過去最大のMCPアップデート! 2026-07-28 RC版の謎に迫る
licux
6
340
Featured
See All Featured
How Software Deployment tools have changed in the past 20 years
geshan
0
34k
How to Build an AI Search Optimization Roadmap - Criteria and Steps to Take #SEOIRL
aleyda
1
2.1k
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
210
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
28
3.5k
AI: The stuff that nobody shows you
jnunemaker
PRO
8
720
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.3k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
62k
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
1
210
Documentation Writing (for coders)
carmenintech
77
5.4k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
6k
Discover your Explorer Soul
emna__ayadi
2
1.1k
Fashionably flexible responsive web design (full day workshop)
malarkey
408
66k
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