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
Game of Developer Life... Deconstructed
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Mariusz Gil
April 03, 2017
Programming
200
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Game of Developer Life... Deconstructed
Mariusz Gil
April 03, 2017
More Decks by Mariusz Gil
See All by Mariusz Gil
Aspect Oriented Programming
mariuszgil
1
350
Designing and implementing GraphQL API
mariuszgil
1
120
Discovering unknown with EventStorming ConFoo
mariuszgil
0
330
Back to forgotten roots
mariuszgil
1
450
Go micro with microservices
mariuszgil
5
720
Machine Learning for the rescue
mariuszgil
0
460
Discovering graph structures
mariuszgil
3
560
Introduction to Aerospike with PHP
mariuszgil
8
880
Processing events at scale
mariuszgil
2
400
Other Decks in Programming
See All in Programming
バグを直したら useEffect が消えた
colorful12
3
780
コンパウンドプロダクト開発のためのローカルプロセスマネージャー再発明 #layerxgo
izumin5210
0
600
ハーネス設計入門 〜プロンプト、コンテキストの次〜
kinopeee
48
31k
Press start. Python's next generation.
willingc
PRO
3
300
MySQLとPostgreSQLって何が違うの?
akagami
0
150
[DroidKaigi 26] How We Moved from Android Studio to Slack
thisaay
0
130
仕様駆動開発の消費期限
watany
20
9.2k
이 함수, 실패하면 어떻게 되나요? null부터 Rich Errors까지, Kotlin 에러 처리 15년
haeti2
0
110
Gmail/Google DriveをトリガーにAIエージェントを動かそう! / Run AI agents with Gmail/Google Drive as triggers!
har1101
3
460
Hello, Hiroshima Geospatial Data! — Exploring DoboX with Python
ra0kley
0
150
FastAPI の並行処理モデルを完全に理解する
hoto17296
9
3.3k
VibeCodingからAgenticWorkflowへ
starfish719
0
1k
Featured
See All Featured
Building the Perfect Custom Keyboard
takai
2
860
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.8k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
10k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.8k
Build The Right Thing And Hit Your Dates
maggiecrowley
39
3.4k
Avoiding the “Bad Training, Faster” Trap in the Age of AI
tmiket
0
220
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
400
Accessibility Awareness
sabderemane
1
190
brightonSEO & MeasureFest 2025 - Christian Goodrich - Winning strategies for Black Friday CRO & PPC
cargoodrich
3
800
New Earth Scene 8
popppiees
3
2.5k
Building Flexible Design Systems
yeseniaperezcruz
330
41k
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
360
Transcript
Deconstructed Game of Life @MariuszGil
None
None
Back to 1970
None
None
None
None
Why game oF...
What How Why When
object oriented
None
None
private function calculateNewCellState($cell, $cellPosition) { $aliveCount = 0; $currentNeighbour =
0; $isFirstColumn = $cellPosition % $this->columns === 0; $isLastColumn = $cellPosition % $this->columns === $this->columns - 1; for ($i = 0; $i < 8; $i++) { $currentNeighbour = $cellPosition + $this->neighbourCoordinates[$i]; if ($currentNeighbour > 0 && ($currentNeighbour < $this->boardLength) && $this->currentGeneration[$currentNeighbour]->getState()) { if (($isFirstColumn && !in_array($i, [0, 3, 5])) || ($isLastColumn && !in_array($i, [2, 4, 7])) || !($isFirstColumn || $isLastColumn)) { $aliveCount++; } } } if ($cell->getState() && ($aliveCount < 2 || $aliveCount > 3)) { return false; } else if (!$cell->getState() && $aliveCount === 3) { return true; } else { return $cell->getState(); } }
protected function setCellDead(int $posN, int $posM) { $this->grid ->getCell($posN, $posM)
->setDead(); } private function onePlay() { $cellsToUpdate = []; for ($n = 0; $n < $this->grid->getSizeN(); $n++) { for ($m = 0; $m < $this->grid->getSizeM(); $m++) { $neighboursCount = $this->grid->getCellNeighboursCount($n, $m); $cellsToUpdate[] = ['n' => $n, 'm' => $m, 'neighbours' => $neighboursCount]; } } foreach ($cellsToUpdate as $cellStruct) { $this->rules->applyForCell($this->grid->getCell($cellStruct['n'], $cellStruct['m']), $cellStruct['neighbours']); } }
public function compute() { $computedGrid = []; foreach ($this->matrix as
$row => $cellArr) { foreach ($cellArr as $col => $cell) { $ns = $this->checkLifeNeighbours($row, $col); $newCell = ($cell === null) ? $this->checkIfAwake($ns) : $this->setCellStatus($cell, $ns); $computedGrid[$row][$col] = $newCell; } } $this->matrix = $computedGrid; } private function setCellStatus(Cell $cell, int $lifeNeighbours) { $newCell = clone($cell); if ($cell->getIsAlive() && ($lifeNeighbours < 2 || $lifeNeighbours > 3)) { $newCell->setIsAlive(false); } elseif (!$cell->getIsAlive() && 3 == $lifeNeighbours) { $newCell->setIsAlive(true); } return $newCell; }
TDD FTW!
Objects identification
Objects ResponsibilitieS
Objects desigN
cell Universe Game Rule Populator Renderer
Patterns and principles object oriented
Domain driven design object oriented Patterns and principles
Functional programming object oriented Patterns and principles Domain driven design
None
apply(state, rules) =
None
None
wrong AssumptionS
Future changeS
2 3
None
4 6
None
private function checkIfAwake($lifeNeighbours) { return (3 == $lifeNeighbours) ? new
Cell(true) : null; } private function checkLifeNeighbours(int $row, int $col) { $life = 0; for ($rowMatrix = $row-1; $rowMatrix <= $row+1; $rowMatrix++) { for ($colMatrix = $col-1; $colMatrix <= $col+1; $colMatrix++) { if ($colMatrix == $col && $rowMatrix == $row) continue; if (isset($this->matrix[$rowMatrix][$colMatrix]) && $this->matrix[$rowMatrix][$colMatrix]->getIsAlive()) { $life++; } } } return $life; }
None
So what?
stability / instability
None
Cancer cell cell Universe Game Rule Populator cli Renderer 2D
Coordinates stronger cell Always alive cell 3D Coordinates Svg Renderer
19 95
to remember
questions? @MariuszGil
None