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
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
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
340
Designing and implementing GraphQL API
mariuszgil
1
110
Discovering unknown with EventStorming ConFoo
mariuszgil
0
320
Back to forgotten roots
mariuszgil
1
430
Go micro with microservices
mariuszgil
5
710
Machine Learning for the rescue
mariuszgil
0
450
Discovering graph structures
mariuszgil
3
560
Introduction to Aerospike with PHP
mariuszgil
8
870
Processing events at scale
mariuszgil
2
390
Other Decks in Programming
See All in Programming
その問い、本当に正しいですか?AI時代のエンジニアに必要な哲学と認知科学 / ai-philosophy-cognitive-science
minodriven
7
4.4k
Java × distroless で 軽量なコンテナイメージを / Java on Distroless
contour_gara
0
540
New "Type" system on PicoRuby
pocke
1
920
Observability in Practice:Grafana 與 Edge Device SRE 的那些事
blueswen
0
160
Spring Security 実践 ─ GraphQL APIで実務に役立つ 認証・認可 を学ぶ
wagyu
0
230
jQueryをバージョンアップする前に使いたいjQuery Migrate
matsuo_atsushi
0
480
Signal Forms: Details & Live Coding @enterJS 2026 in Mannheim
manfredsteyer
PRO
0
130
TAKTでAI駆動開発の品質を設計する
j5ik2o
6
1.3k
ユニットテストの先へ:テスト技法で要求・仕様を整理するJava開発実践 / Beyond_Unit_Testing_Practical_Java_Development_Techniques_for_Organizing_Requirements_and_Specifications
shimashima35
0
400
The ROI of Quarkus for Spring Boot Applications
hollycummins
0
120
キャリア迷子上等 ─ "ない道"は自分で作ればいい
16bitidol
3
2.1k
エンジニアと一緒にテストコードの設計と実装を改善した話
mototakatsu
0
170
Featured
See All Featured
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
1
140
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.4k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
230
23k
JAMstack: Web Apps at Ludicrous Speed - All Things Open 2022
reverentgeek
1
470
Context Engineering - Making Every Token Count
addyosmani
9
960
WENDY [Excerpt]
tessaabrams
11
38k
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.6k
HDC tutorial
michielstock
2
710
First, design no harm
axbom
PRO
2
1.2k
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
340
Code Reviewing Like a Champion
maltzj
528
40k
Designing for Performance
lara
611
70k
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