Subscribe to PHP Freaks RSS

Poka Yoke – Saving Projects with Hyper-Defensive Programming

syndicated from planet-php.net on June 28, 2017

When working in a medium to large team on the same codebase, it can sometimes become hard to understand each other's code and how to use it. Various solutions exist to help with this. For example, you can agree to follow a set of coding standards to make the code more readable for each other, or use a framework that's known to all (we've got a great Laravel intro premium course here).

However, this is often not enough, especially when someone has to dig back into a part of the application written some time ago to fix a bug or add a new feature. It can be quite hard to remember how particular classes were intended to work, both on their own and in combination with each other. At that point, it becomes easy to accidentally introduce side effects or bugs without realizing it.

A detected bug

These mistakes might get caught in quality assurance, but there's a realistic chance they might slip through. And even if they get caught, it can take a lot of time to send the code back and get it fixed.

So how can we prevent this? Enter "Poka Yoke".

What is Poka Yoke?

Poka Yoke is a Japanese term which roughly translates to "mistake-proofing". The term
originated in lean manufacturing, where it refers to any mechanism that helps a machine operator avoid mistakes.

Outside of manufacturing, Poka Yoke is also often used in consumer electronics. Take, for example, a SIM card, which can only fit one way a sim tray because of its asymmetrical shape.

A SIM card and tray, illustrating how the SIM card can ></p>
<p>An example of hardware lacking in Poka Yoke is the PS/2 port, which has exactly the same shape for a keyboard connector and a mouse connector. They can only be differentiated by using color codes, so it is easy to accidentally switch the connectors and insert them in the wrong ports because they both fit the same way.</p>
<p><img src=the original (another 3780 bytes)