Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Speaker Deck
PRO
Sign in
Sign up for free
Game of Developer Life... Deconstructed
Mariusz Gil
April 03, 2017
Programming
1
140
Game of Developer Life... Deconstructed
Mariusz Gil
April 03, 2017
Tweet
Share
More Decks by Mariusz Gil
See All by Mariusz Gil
Aspect Oriented Programming
mariuszgil
1
220
Designing and implementing GraphQL API
mariuszgil
1
33
Discovering unknown with EventStorming ConFoo
mariuszgil
0
170
Back to forgotten roots
mariuszgil
1
310
Go micro with microservices
mariuszgil
5
450
Machine Learning for the rescue
mariuszgil
0
300
Discovering graph structures
mariuszgil
3
470
Introduction to Aerospike with PHP
mariuszgil
8
580
Processing events at scale
mariuszgil
2
330
Other Decks in Programming
See All in Programming
もしも、 上司に鬼退治を命じられたら~プロジェクト計画編~
higuuu
0
270
質とスピード(2022春版、質疑応答用資料付き) / Quality and Speed 2022 Spring Edition
twada
PRO
27
17k
Managing gRPC with Wire
oldergod
2
150
競プロへの誘 -いざな-
u76ner
0
330
職場にPythonistaを増やす方法
soogie
0
180
脱オブジェクト指向講座(5分LT資料)
kishida
8
11k
Language Summit 2022: WebAssembly: Python in the browser and beyond
tiran
2
310
mrubyを1300円のボードで動かそう
yuuu
0
180
LOWYAの信頼性向上とNew Relic
kazumax55
4
330
Develop your CI tools
xgouchet
2
180
コードの解析と言語習得の心得
jinjin33333
0
120
Explore Java 17 and beyond
josepaumard
3
630
Featured
See All Featured
Building Applications with DynamoDB
mza
83
4.6k
Automating Front-end Workflow
addyosmani
1351
200k
WebSockets: Embracing the real-time Web
robhawkes
57
5k
Streamline your AJAX requests with AmplifyJS and jQuery
dougneiner
125
8.5k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
15
910
Code Reviewing Like a Champion
maltzj
506
37k
What's new in Ruby 2.0
geeforr
336
30k
Producing Creativity
orderedlist
PRO
333
37k
The Brand Is Dead. Long Live the Brand.
mthomps
45
2.7k
How To Stay Up To Date on Web Technology
chriscoyier
780
250k
Bootstrapping a Software Product
garrettdimon
295
110k
Designing on Purpose - Digital PM Summit 2013
jponch
106
5.6k
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