# Eliminating Visual Debt

DevFeed: [Eliminating Visual Debt](<https://devfeed.tech/articles/eliminating-visual-debt-21142.md>)

Original publisher: [Read original article](<https://ocramius.github.io/blog/eliminating-visual-debt/>)

Published: 2017-05-29T00:00:00Z

Content type: opinion

Language: en

Sources: [Marco Pivetta](<https://devfeed.tech/sources/marco-pivetta.md>)

Topics: [PHP](<https://devfeed.tech/topics/php.md>), [Code](<https://devfeed.tech/topics/code.md>), [coding](<https://devfeed.tech/topics/coding.md>), [Polymorphism](<https://devfeed.tech/topics/polymorphism.md>)

Tags: [code](<https://devfeed.tech/tags/code.md>), [implementation](<https://devfeed.tech/tags/implementation.md>), [inheritance](<https://devfeed.tech/tags/inheritance.md>), [php](<https://devfeed.tech/tags/php.md>)

## AI overview

The article examines "visual debt" in PHP code and argues for questioning conventional coding practices. It demonstrates progressively removing type declarations, runtime checks, contracts, meaningful names, and inheritance restrictions from an event system, emphasizing reduced visual and engine overhead while discussing the tradeoff with code clarity and declarative guidance.

## Source excerpt

Today we're talking about Visual debt in our code. As an introduction, I suggest to watch this short tutorial about visual debt by @jeffrey_way. The concept is simple: let's take the example from Laracasts and re-visit the steps taken to remove visual debt. interface EventInterface { public function listen(string $name, callable $handler) : void; public function fire(string $name) : bool; } final class Event implements EventInterface { protected $events = []; public function listen(string $name, callable $handler) : void { $this->events[$name][] = $handler; } public function fire(string $name) : bool { if (! array_key_exists($name, $this->events)) { return false; } foreach ($this->events[$name] as $event) { $event(); } return true; } } $event = new Event; $event->listen('subscribed', function () { var_dump('handling it'); }); $event->listen('subscribed', function () { var_dump('handling it again'); }); $event->fire('subscribed'); So far, so good. We have an event that obviously fires itself, a concrete implementation and a few subscribers. Our code works, but it contains a lot of useless artifacts that do not really influence our ability to make it run. These artifacts are also distracting, moving our focus from the runtime to the declarative requirements of the code. Let's start removing the bits that aren't needed by starting from the method parameter and return type declarations: interface EventInterface { public function listen($name, $handler); public function fire($name); } final class Event implements EventInterface { protected $events = []; public function listen($name, $handler) { $this->events[$name][] = $handler; } public function fire($name) { if (! array_key_exists($name, $this->events)) { return false; } foreach ($this->events[$name] as $event) { $event(); } return true; } } Our code is obvious, so the parameters don't need redundant declarations or type checks. Also, we are aware of our own implementation, so the runtime checks are not needed, as the