Upgrade to Pro — share decks privately, control downloads, hide ads and more …

HOW TO SURVIVE: THE ENDLESS FUN THAT IS LEGACY CODE

HOW TO SURVIVE: THE ENDLESS FUN THAT IS LEGACY CODE

The first step of working with legacy code is realising the incredible amount of value that has dropped in you lap.
In this talk we are going to pinpoint that value. And move that value in a better to maintain and understand codebase.

First we will cover the general mentality that will make it easier to prepare a plan of attack.
Next up are more technical tips that will make it easier to talk about the code.
We will end off the session with actually porting a small piece of code.

Frederick Vanbrabant

August 28, 2018
Tweet

More Decks by Frederick Vanbrabant

Other Decks in Technology

Transcript

  1. HOW TO SURVIVE: HOW TO SURVIVE: THE ENDLESS FUN THE

    ENDLESS FUN THAT IS LEGACY THAT IS LEGACY CODE CODE
  2. "INHERENT VALUE OF THE CODE "INHERENT VALUE OF THE CODE

    RULES EVERYTHING AROUND ME" RULES EVERYTHING AROUND ME" - THE WU TANG CLAN - THE WU TANG CLAN
  3. “ MOVE FAST AND BREAK MOVE FAST AND BREAK THINGS.

    UNLESS YOU ARE THINGS. UNLESS YOU ARE BREAKING STUFF, YOU ARE NOT BREAKING STUFF, YOU ARE NOT MOVING FAST ENOUGH. MOVING FAST ENOUGH.
  4. “ MOVE FAST AND BREAK MOVE FAST AND BREAK THINGS.

    UNLESS YOU ARE THINGS. UNLESS YOU ARE BREAKING STUFF, YOU ARE NOT BREAKING STUFF, YOU ARE NOT MOVING FAST ENOUGH. MOVING FAST ENOUGH. - Guy that never worked on legacy code
  5. GET YOUR BUILDS, GIT AND GET YOUR BUILDS, GIT AND

    DEPLOYS UNDER CONTROL DEPLOYS UNDER CONTROL
  6. End to end test End to end test End to

    end test End to end test
  7. End to end test End to end test End to

    end test End to end test Shiny new code
  8. End to end test End to end test End to

    end test End to end test Shiny new code ? ?
  9. <?php * A million things * $conn = new mysqli('catInc',

    'root', 'hunter2', 'main'); if ($conn->connect_error) { die("Connection failed"); } $sql = "INSERT INTO Cats (name) VALUES ('Thoru')"; $conn->query($sql) $conn->close(); * A million things *
  10. <?php class KittenTranslationLayer { public static function addCat($name) { $container

    = App::getContainer(); $catRepository = $container ->get(CatRepository::class); $catRepository->addCat(new CatName($name)); } }
  11. <?php class CatRepository { private $connection; public function __construct(Connection $connection)

    { $this->connection = $connection; } public function addCat(CatName $name) { $query = $this->connection ->createQueryBuilder(); $query->insert('cats') ->setValue('name', ':name') ->setParameter('name', $name) ->execute();
  12. <?php * A million things * $conn = new mysqli('catInc',

    'root', 'hunter2', 'main'); if ($conn->connect_error) { die("Connection failed"); } $sql = "INSERT INTO Cats (name) VALUES ('Thoru')"; $conn->query($sql) $conn->close(); * A million things *
  13. WE AREN'T DONE YET WE AREN'T DONE YET THROW SOME

    DDD AT IT THROW SOME DDD AT IT
  14. App/ ├── Controllers/ │ ├── UserControler.php │ └── PostController.php ├──

    Models/ │ ├── User.php │ └── Post.php ├── Validators/ │ ├── UserCreate.php │ ├── UserUpdate.php │ ├── PostCreate.php │ └── PostUpdate.php └── Transformers/ ├── User.php └── Post.php
  15. App/ ├── Controllers/ │ ├── UserControler.php │ └── PostController.php ├──

    Models/ │ ├── User.php │ └── Post.php ├── Validators/ │ ├── UserCreate.php │ ├── UserUpdate.php │ ├── PostCreate.php │ └── PostUpdate.php └── Transformers/ ├── User.php └── Post.php App/ ├── Http/ │ ├── UserControler.php │ └── PostController.php ├── User/ │ ├── Validators/ │ ├── ├── Create.php │ ├── └── Update.php │ ├── Transformer.php │ └── User.php └── Post/ ├── Validators/ ├── ├── Create.php ├── └── Update.php ├── Transformer.php └── Post.php
  16. <?php class UserController { private $repo; public function __construct(UserRepository $repo)

    { $this->repo = $repo; } public function update() { $this->repo->setAmountOfCats(?, ?); } }
  17. <?php class UserId implements IdInterface { public function __constructor(int $id)

    { if ($id < 1) { throw new InvalidIdException(); } $this->id = $id; } public function getValue(); public function getAsUUID(); }
  18. GUESS I'M NOW A GUESS I'M NOW A LEGACY CODE

    LEGACY CODE DEVELOPER DEVELOPER
  19. LEARN MORE? LEARN MORE? Modernizing Legacy Applications In PHP -

    PM Jones Working Effectively with Legacy Code - Michael Feathers The League of Extraordinary Packages