Q: I’m a beginner stepping into a massive and old PHP codebase, what should I expect?

There is no point in trying to sugar-coat this.

What you can probably expect, unless you are really lucky,  is a giant smelly hairy mEsS. You will probably find yourself dumped into the middle of a tangle of unreadable, untestable and unstable code wedged dangerously between at least two outdated PHP frameworks, half a dozen or so JavaScript frameworks and an abandoned half-baked experimental framework. It will seem like the only thing keeping the whole contraption from collapsing is some deeply sinister black magic of which no mere mortal can conceive.

You can also expect your first reaction to this abomination to be utter disgust and recoil. This will be probably be followed, shortly after by an overwhelming and determined desire to jump in and fix the whole bloody thing, to chop it down at the roots and rebuild it from the ground up.  Every piece of code you see will be festering with ugliness and wrongness and every other kind of technical unholiness.

You will also start to notice that for every rusted nail you suddenly seem to have a ready hammer. Every technique,  pattern, tool and framework you have in your mental toolkit will suddenly find a hole to plug, much like the tortured metaphors in this post.

The best you can do when this starts happening is to stop. Stop and feel the urges, feel them writhing in your gut. Then by any means necessary make sure that you DO NOT ACT on them. Drop your hammer and your sword and your axe. This is not a time for heroics.

It’s important to remember that you did not only inherit a code-base. You also very likely inherited a user base. Even if you don’t currently have any active users, you hopefully plan on having some very soon, right? In either case, your Users should be a primary driving force in any decision you make.

You need to focus on what your Users need. Specifically, you need to focus on what they need right now.

The thing your Users need right now is almost never a shiny new framework or perfectly clean code or a rapidly cascading refactoring effort. They need you to fix the most pressing bugs and implement the most overdue features. They need you to do this as quickly as possible and in a way that minimises disruption.

Safely making big sweeping changes to any complicated system requires a fairly thorough understanding of that system. When starting on a project like this you are not going to have a sufficient level of understanding and gaining it usually takes time. Your users, unfortunately, don’t have time to wait for you to figure out the system while they need things to get done. They also are not going to wait around if you prematurely make big drastic changes and things go wrong because there are important things you missed or did not understand.

Your best option, therefore, is to jump in, start working and work with what you have. As you make your changes write good, clean code, but importantly keep it localised, sensible and coherent within the context of the existing code that surrounds it.

What this all implies is that you need to prepare yourself for a difficult choice. Soon you are going to find yourself surrounded by the Complexity and Chaos that is your code base. You are going to have to choose to stay, stand there immersed in the Chaos and start working with it rather than against it.

Start preparing yourself for this choice now.

Choosing to work in the Chaos does not mean that you are turning your back on Order. You will not have to live in this place forever. You do not have to forget your weapons and your tools, they will all prove useful in time. Every day that you labour in the belly of the beast, you are gradually and carefully getting to know it, discovering every nook and cranny, every seam and smell. You are slowly building up a mental model and drawing a detailed map of its twisted insides. Then, in time, as you start to see it more clearly and completely, you will start hatching a plan…

The strategy you develop may be to launch a savage attack and slay the monster.  It may be to gradually make her over into a graceful princess. The point is that this is not an undertaking you should make from a position of ignorance.

This choice, to focus on the what is necessary rather than what is interesting, sexy and exiting is not an easy one. It is also a choice you will have to make constantly, every time you stare at a piece of code and wonder what next to do. But in the long run, it’s the right decision, for you and your Users.

If you ever need something to help you stay on the path, a simple reason to keep you making the right choice, remember this one thing:

Your code-base is such a mess, in the first place, because everyone before you chose to do differently.

Did this help you?

Sign up for my newsletter and I will send you regular articles and other goodies.

Sign Me Up!

You can unsubscribe at any time

Share this:

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.