Slide 1

Slide 1 text

The Subtle Art of Naming ___ Julien Janvier @jujanvier https://joind.in/talk/b59b0

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

class PeasCounter { public function count(Bucket $bucket) { $peasCount = 0; foreach ($bucket->getPeaShells() as $peaShell) { $openedPeaShell = $this->peaShellOpener->open($peaShell); foreach ($openedPeaShell->getPeas() as $pea) { $peasCount++; } } return $peasCount; } } 01 02 03 04 05 06 07 08 09 10 11 12 13

Slide 4

Slide 4 text

class PeasCounter { public function count(Bucket $bucket) { $peasCount = 0; foreach ($bucket->getPeaShells() as $peaShell) { $openedPeaShell = $this->peaShellOpener->open($peaShell); foreach ($openedPeaShell->getPeas() as $pea) { $peasCount++; } } return $peasCount; } } 01 02 03 04 05 06 07 08 09 10 11 12 13

Slide 5

Slide 5 text

class PeasCounter { public function count(Bucket $bucket) { $peasCount = 0; foreach ($bucket->getPeaShells() as $peaShell) { $openedPeaShell = $this->peaShellOpener->open($peaShell); foreach ($openedPeaShell->getPeas() as $pea) { $peasCount++; } } return $peasCount; } } 01 02 03 04 05 06 07 08 09 10 11 12 13

Slide 6

Slide 6 text

class PeasCounter { public function count(Bucket $bucket) { $peasCount = 0; foreach ($bucket->getPeaShells() as $peaShell) { $openedPeaShell = $this->peaShellOpener->open($peaShell); foreach ($openedPeaShell->getPeas() as $pea) { $peasCount++; } } return $peasCount; } } 01 02 03 04 05 06 07 08 09 10 11 12 13

Slide 7

Slide 7 text

class PeasCounter { public function count(Bucket $bucket) { $peasCount = 0; foreach ($bucket->getPeaShells() as $peaShell) { $openedPeaShell = $this->peaShellOpener->open($peaShell); foreach ($openedPeaShell->getPeas() as $pea) { $peasCount++; } } return $peasCount; } } 01 02 03 04 05 06 07 08 09 10 11 12 13

Slide 8

Slide 8 text

class PeasCounter { public function count(Bucket $bucket) { $peasCount = 0; foreach ($bucket->getPeaShells() as $peaShell) { $openedPeaShell = $this->peaShellOpener->open($peaShell); foreach ($openedPeaShell->getPeas() as $pea) { $peasCount++; } } return $peasCount; } } 01 02 03 04 05 06 07 08 09 10 11 12 13

Slide 9

Slide 9 text

class PeasCounter { public function count(Bucket $bucket) { $peasCount = 0; foreach ($bucket->getPeaShells() as $peaShell) { $openedPeaShell = $this->peaShellOpener->open($peaShell); foreach ($openedPeaShell->getPeas() as $pea) { $peasCount++; } } return $peasCount; } } 01 02 03 04 05 06 07 08 09 10 11 12 13 $peasCounter = new PeasCounter(...); $peasCount = $peasCounter->count($bucket);

Slide 10

Slide 10 text

anemic models rich models

Slide 11

Slide 11 text

foreach ($bucket->getPeaShells() as $peaShell) { $openedPeaShell = $this->peaShellOpener->open($peaShell);

Slide 12

Slide 12 text

foreach ($bucket->getPeaShells() as $peaShell) { $openedPeaShell = $this->peaShellOpener->open($peaShell); $openedPeaShell = $peaShell->open();

Slide 13

Slide 13 text

imperative declarative

Slide 14

Slide 14 text

$counter = new PeasCounter(); $peasCount = $counter->count($bucket);

Slide 15

Slide 15 text

$counter = new PeasCounter(); $peasCount = $counter->count($bucket); class PeasCounter { public function count(Bucket $bucket): int { } }

Slide 16

Slide 16 text

$peasCount = CountPeas($bucket); // ideally

Slide 17

Slide 17 text

$peasCount = (new CountPeas)($bucket);

Slide 18

Slide 18 text

$peasCount = (new CountPeas)($bucket); class CountPeas { public function __invoke(Bucket $bucket): int { } }

Slide 19

Slide 19 text

developer jargon natural language

Slide 20

Slide 20 text

interface CountPeasInterface { //... }

Slide 21

Slide 21 text

interface CountPeasInterface { //... } class CountPeas implements CountPeasInterface { //... }

Slide 22

Slide 22 text

interface SomeRandomBehaviorInterface class AnImplementationThatFollowsThisPattern class SomethingBadHappenedException extends \Exception

Slide 23

Slide 23 text

interface CountPeas { //... }

Slide 24

Slide 24 text

interface CountPeas { //... } class PenAndPaper implements CountPeas { //… }

Slide 25

Slide 25 text

interface CountPeas { //... } class PenAndPaper implements CountPeas { //… } class InMemory implements CountPeas { //… }

Slide 26

Slide 26 text

interface CountPeas { public function countPeas(Bucket $bucket): int; } class PenAndPaper implements CountPeas { //… } class InMemory implements CountPeas { //… }

Slide 27

Slide 27 text

look for perfection tell the (hard) truth

Slide 28

Slide 28 text

interface EntityWithFamilyInterface {}

Slide 29

Slide 29 text

interface EntityWithFamilyInterface {} interface ReserveSeats {} function doesNotExceedOverallTrainCapacityLimit($seatsRequestedCount)

Slide 30

Slide 30 text

No content

Slide 31

Slide 31 text

class PenAndPaper implements CountPeas { public function countPeas(Bucket $bucket): int { foreach ($bucket->peaShells() as $peaShell) { foreach ($peaShell->open()->peas() as $pea) { $this->drawOneStick(); } } return $this->countSticks(); } } 01 02 03 04 05 06 07 08 09 10 11 12

Slide 32

Slide 32 text

class PenAndPaper implements CountPeas { public function countPeas(Bucket $bucket): int { foreach ($bucket->peaShells() as $peaShell) { foreach ($peaShell->open()->peas() as $pea) { $this->drawOneStick(); } } return $this->countSticks(); } } 01 02 03 04 05 06 07 08 09 10 11 12

Slide 33

Slide 33 text

class PenAndPaper implements CountPeas { public function countPeas(Bucket $bucket): int { foreach ($bucket->peaShells() as $peaShell) { foreach ($peaShell->open()->peas() as $pea) { $this->drawOneStick(); } } return $this->countSticks(); } } 01 02 03 04 05 06 07 08 09 10 11 12

Slide 34

Slide 34 text

class PenAndPaper implements CountPeas { public function countPeas(Bucket $bucket): int { foreach ($bucket->peaShells() as $peaShell) { foreach ($peaShell->open()->peas() as $pea) { $this->drawOneStick(); } } return $this->countSticks(); } } 01 02 03 04 05 06 07 08 09 10 11 12

Slide 35

Slide 35 text

class PenAndPaper implements CountPeas { public function countPeas(Bucket $bucket): int { foreach ($bucket->peaShells() as $peaShell) { foreach ($peaShell->open()->peas() as $pea) { $this->drawOneStick(); } } return $this->countSticks(); } } 01 02 03 04 05 06 07 08 09 10 11 12

Slide 36

Slide 36 text

class PenAndPaper implements CountPeas { public function countPeas(Bucket $bucket): int { foreach ($bucket->peaShells() as $peaShell) { foreach ($peaShell->open()->peas() as $pea) { $this->drawOneStick(); } } return $this->countSticks(); } } 01 02 03 04 05 06 07 08 09 10 11 12 $penAndPaper = new PenAndPaper(); $countPeas = $penAndPaper->countPeas($bucket);

Slide 37

Slide 37 text

The Subtle Art of Naming ___ Julien Janvier @jujanvier https://joind.in/talk/b59b0

Slide 38

Slide 38 text

Don’t name, Describe ___ Julien Janvier @jujanvier https://joind.in/talk/b59b0