Slide 1

Slide 1 text

and the Evil Architects @mheap at #tek16

Slide 2

Slide 2 text

Antikythera Mechanism

Slide 3

Slide 3 text

It’s Been Stolen!

Slide 4

Slide 4 text

Why do we want it?

Slide 5

Slide 5 text

40-80% of a project is maintenance

Slide 6

Slide 6 text

Why so much?

Slide 7

Slide 7 text

Our job is to read code, Not to write it

Slide 8

Slide 8 text

*flying noises*

Slide 9

Slide 9 text

Where do we start?

Slide 10

Slide 10 text

What should be saved?

Slide 11

Slide 11 text

What is dangerous?

Slide 12

Slide 12 text

Who created this?

Slide 13

Slide 13 text

README.md

Slide 14

Slide 14 text

Talk to people

Slide 15

Slide 15 text

Inventory the code

Slide 16

Slide 16 text

Dependencies

Slide 17

Slide 17 text

Build the project

Slide 18

Slide 18 text

Accept you're missing 10%

Slide 19

Slide 19 text

Time to go in!

Slide 20

Slide 20 text

Security!

Slide 21

Slide 21 text

“Incorrect Password”

Slide 22

Slide 22 text

$ grep -lr "Incorrect password" * src/Architect/Security/DoorPasswordValidator.php

Slide 23

Slide 23 text

namespace Architect\Security; class DoorPasswordValidator { private $doorPassword = 'shibboleet'; public function validate($input) { if ($this->doorPassword !== $input) { throw new \Exception("Incorrect password"); } return true; } }

Slide 24

Slide 24 text

We’re in!

Slide 25

Slide 25 text

Navigation

Slide 26

Slide 26 text

Draw a map

Slide 27

Slide 27 text

No content

Slide 28

Slide 28 text

Read the code

Slide 29

Slide 29 text

Don’t trust the comments

Slide 30

Slide 30 text

namespace Architect\Game; class Roulette { /** * Returns a random number */ }

Slide 31

Slide 31 text

Don’t trust the code

Slide 32

Slide 32 text

namespace Architect\Game; class Roulette { /** * Returns a random number */ private function spinRandom(){ return 4; } }

Slide 33

Slide 33 text

Does this code even run?

Slide 34

Slide 34 text

/** * Returns a random number */ private function spinRandom() { die('Yes it does'); return 4; }

Slide 35

Slide 35 text

Look for side effects

Slide 36

Slide 36 text

public function triggerFireAlarm() { $this->startSprinklers(); $this->callFireBrigade(); $this->releaseDoorLocks(); }

Slide 37

Slide 37 text

Naming Things

Slide 38

Slide 38 text

Find intentions

Slide 39

Slide 39 text

Find Patterns

Slide 40

Slide 40 text

Prove you understand it

Slide 41

Slide 41 text

I don’t understand it

Slide 42

Slide 42 text

Debugging

Slide 43

Slide 43 text

use everything

Slide 44

Slide 44 text

Everything goes

Slide 45

Slide 45 text

DDD

Slide 46

Slide 46 text

Die Driven Debugging

Slide 47

Slide 47 text

echo '######################'.PHP_EOL; echo $currentCasinoCapacity; echo '######################'.PHP_EOL;

Slide 48

Slide 48 text

if (!isset($visitors['derick_rethans'])){ var_dump($visitors);die; }

Slide 49

Slide 49 text

echo '######################'.PHP_EOL; var_dump(debug_backtrace()); echo '######################'.PHP_EOL;

Slide 50

Slide 50 text

class MyDoorMan extends DoorMan { public function changeShiftAt($val) { throw new Exception("Changing at $val"); } }

Slide 51

Slide 51 text

XDebug

Slide 52

Slide 52 text

XDebug.scream

Slide 53

Slide 53 text

XDebug_break();

Slide 54

Slide 54 text

if (!isset($visitors['derick_rethans'])){ xdebug_break(); }

Slide 55

Slide 55 text

xdebug_debug_zval();

Slide 56

Slide 56 text

$michael = new Person(‘Michael’); $bouncer =& $michael; $dealer =& $michael->hands; xdebug_debug_zval( 'michael' ); // Outputs michael: (refcount=2, is_ref=1)=array ( 0 => (refcount=1, is_ref=0)=1, 1 => (refcount=1, is_ref=0)=2, 2 => (refcount=2, is_ref=1)=3)

Slide 57

Slide 57 text

XHPROF

Slide 58

Slide 58 text

DDD +X Debug + XHProf == WINNING

Slide 59

Slide 59 text

Observer Effect

Slide 60

Slide 60 text

I’m feeling better

Slide 61

Slide 61 text

Project History

Slide 62

Slide 62 text

git log -S

Slide 63

Slide 63 text

git log -S antikythera

Slide 64

Slide 64 text

commit 5288d5804a3fc20dae4f3b2deeaa7f687595aff1 Author: Eli White Date: Tue May 24 09:33:59 2016 +0000 Add new secure storage facility. (Closes #42) The existing storage facilities use symmetrical encryption keys which allow anyone with the password to access them. The new storage is more secure and requires both a password and my handprint. There’s nothing in there yet but we’ll put the Antikythera in it as soon as it arrives

Slide 65

Slide 65 text

What’s changed recently?

Slide 66

Slide 66 text

Temporal Coupling

Slide 67

Slide 67 text

Explicit

Slide 68

Slide 68 text

commit 0dc164fb052f4b838a674648aa29d83b60f01fa2 Author: Oscar Merida Date: Fri May 20 12:14:55 2016 +0000 Changed from European to American roulette table. Gives the house a better edge 5 2 src/Architect/Game/Roulette.php 14 0 test/Architect/Game/RouletteTest.php

Slide 69

Slide 69 text

Implicit

Slide 70

Slide 70 text

commit 2915dabebc8b87b84ec40fac0f4954fb84f3b7cd Author: Eli White Date: Sun May 22 21:27:31 2016 +0000 Removed the corner roulette table as it was crooked. Updated Fire plan to remove table 0 2 src/Architect/FloorPlan.php 0 1 src/Architect/Policy/FireEscape.php

Slide 71

Slide 71 text

Common Causes

Slide 72

Slide 72 text

Code Maat

Slide 73

Slide 73 text

statistic,value number-of-commits,2254 number-of-entities,3179 number-of-entities-changed,9979 number-of-authors,106

Slide 74

Slide 74 text

entity,n-authors,n-revs src/Room/VipLounge.php,26,181 src/Game/Blackjack.php,22,76 src/Controller/CloakroomController.php,21,110 src/People/FloorManager.php,19,91

Slide 75

Slide 75 text

entity,age-months src/Security/PasswordManager.php,1 src/Bar/DrinkPrices.php,1 src/Game/Poker/Stud.php,3 src/Security/RadioChannels.php,7

Slide 76

Slide 76 text

entity,coupled,degree,average-revs src/Manager/FloorManager.php,src/Factory/TableFactory.php,100,19 src/Vendor/Drinks.php,src/Vendor/Snacks.php,60,10 src/Room/VipLounge.php,src/Room/Cloakroom,14,172

Slide 77

Slide 77 text

entity,coupled,degree,average-revs application/config/config.php,application/config/database.php,90,6

Slide 78

Slide 78 text

History Analysis is flawed

Slide 79

Slide 79 text

Leaving a legacy

Slide 80

Slide 80 text

Secure the site

Slide 81

Slide 81 text

Rosetta Stone

Slide 82

Slide 82 text

Logging

Slide 83

Slide 83 text

Name things well

Slide 84

Slide 84 text

Build a knowledge map

Slide 85

Slide 85 text

Leave useful comments

Slide 86

Slide 86 text

// // Dear maintainer: // // Once you are done trying to 'optimize' this routine, // and have realized what a terrible mistake that was, // please increment the following counter as a warning // to the next guy: // // total_hours_wasted_here = 42 // I’ve been @mheap, you’ve been awesome! https://joind.in/17041