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
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
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
400
Other Decks in Programming
See All in Programming
気づいたらRubyで100作品 ー クリエイティブコーディングが生活の一部になるまで / 100 Ruby Sketches Later: How Creative Coding Became Part of My Life
chobishiba
3
610
OSもどきOS
arkw
0
590
エンジニアと一緒にテストコードの設計と実装を改善した話
mototakatsu
0
220
AI時代のUIはどこへ行く?その2!
yusukebe
22
7.5k
キャリア迷子上等 ─ "ない道"は自分で作ればいい
16bitidol
3
2.3k
Semantic Version 単位で戦略を柔軟に変えて、パッケージアップデートを自動化する
daitasu
1
300
LaravelLive Japan の裏方のすべて — 第188回 PHP勉強会@東京 (2026-06-24)
suguruooki
2
120
PHPで使える日時の表現と、その知り方 #frontend_phpcon_do
o0h
PRO
0
260
コンテキストの使い捨てをやめる — ビジネスルール駆動開発と miko —
ioki
0
240
Vite+ Unified Toolchain for the Web
naokihaba
0
360
Performance Engineering for Everyone
elenatanasoiu
0
230
ローカルLLMでどこまでコードが書けるか -拡張版 / How much code can be written on a local LLM Extended
kishida
12
4.4k
Featured
See All Featured
Mobile First: as difficult as doing things right
swwweet
225
10k
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
190
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
1
210
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
2k
Intergalactic Javascript Robots from Outer Space
tanoku
273
27k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
16k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
140
B2B Lead Gen: Tactics, Traps & Triumph
marketingsoph
0
160
The Curse of the Amulet
leimatthew05
2
13k
DBのスキルで生き残る技術 - AI時代におけるテーブル設計の勘所
soudai
PRO
66
55k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.5k
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