Is WordPress Code Really a Mess?

WordPress receives a lot of flak for the state its code is in. I was doing some research on Themeosis for an upcoming article and bumped into an article.

The post Is WordPress Code Really a Mess? appeared first on Kinsta Managed WordPress Hosting.

Spread the love

The author said:

My dislike of WordPress is no secret. I look down on its mess of a code base, and advise anyone with any technical knowhow whatsoever against using it.

Is the situation that dire? Is the WordPress core code really so atrocious that you should steer clear altogether and use something else for your project? In this article I’ll take a look at the issue and help pour some clarity on it.

What Is Bad Code?

I think the fundamental issue is that noone really says what bad and messy code is. On paper something like “messy code” sounds horrible, but does a casual reader know what that means? More importantly, does she/he care?

As always, there is a little more to it than that. There are a few properties that could make code “bad”, here are just a few:

  1. Unoptimized code which performs slowly compared to optimized code
  2. Mixing coding styles within a project
  3. Spaghetti code which can only be understood by the author
  4. Unextendable that doesn’t play nice with others

WordPress is indeed guilty of one and a half of these. The coding style is all over the place, that’s for sure. Function names are inconsistent, some modules use a strict object oriented approach, some modules use procedural code, many files don’t use WordPress’ own style guide, – just a few issues.

This means that WordPress uses spaghetti code somewhat, but apart from being annoying it’s not a problem because literally thousands upon thousands understand it since it is such a widely used product.

So is WordPress badly coded? Yes, in the same way as the International Space Station uses bad laptops. Both statements are objectively true but there’s a bit more going on behind the scenes.

The real question is, does this matter?

Coders Don’t Matter

At every WordCamp I go to I get asked the question: would it be great if WordPress switched to a fully OOP approach. The programmer in me says, yes of course, it would be the happiest day in my life. The rational person in me (definitely not the programmer) preaches caution since this move would directly contradict everything WordPress stands for.

As programmers we have to remember that WordPress – at the end of the day – is for the users, not for us. You may think that spending 100+ hours on a project is a lot but the person who uses your work may spend 8 hours a day using it which would amount to 3,000+ hours a year, and that’s only if your work is used by a single user.

As programmers we have to remember that WordPress at the end of the day is for the users. Click to Tweet

Users Don’t Care

Users really don’t care about anything related to code. They want something that is user friendly, fast and secure. WordPress does very well on all three. You can argue that badly coded plugins can ruin WordPress’ speed and safety but that’s like saying my Volvo wasn’t safe because I got injured driving 180 miles an hour into a wall.

Coder’s Aren’t Affected

The vast majority of people who work with WordPress aren’t affected by this issue, or at least don’t have to be. There is simply no situation where you would need to touch core code for a project. This means that you won’t be affected by the messiness of the core code at all.

The only argument coders could have against WordPress is that it doesn’t follow an MVC (model-view-controller) architecture. This is a completely valid criticism, but it’s not like MVC is the only way to write clean code.

In fact, you can use a full on object-oriented approach in plugins and even use and MVC-like structure if you prefer. The real problem is with themes which are built in a way that you can’t just inject MVC principles.

That said, themes follow strict guidelines and are well structured, despite not being MVC. This boils down to a common vein in every theme which makes it easy to work with them if you know what you’re doing.

Is It Possible to Write Good Code?

The issue is not wether WordPress core code is good or bad. WordPress core code is somewhat of a mess, but it is still good code. This doesn’t mean it couldn’t be vastly improved but for the purposes, it serves it is great.

The issue is: is it possible to write good code with WordPress. The answer is a resounding yes. As I mentioned earlier, plugins are free-form so you can do whatever you like there, including OOP.

I do also want to stress that OOP is not a cure-all. For simple plugins, a well laid out procedural approach may be a lot clearer.

Did you know that WordPress now powers over 31% of all websites?

Kinsta is proud to have worked with some of the biggest names in the industry, such as GE, Intuit, TripAdvisor, and Mint. Our WordPress hosting solution is truly one of a kind, powering businesses of all sizes!

Themes do mix presentation with logic, this is undoubtedly a bad practice. However, the guidelines for themes are well laid out and with some planning a structuring you can write a logical and easy to follow theme.

With the advent of the WordPress API all other criticisms go down the drain because you can pretty much use the data in the database anywhere. You could use Laravel for everything and pull in the data via the WordPress API.

Summary

So at the end of the day, is WordPress code a mess? Yes, some of it is. Some plugins and themes really do contain bad code and hinders the community as a whole. Like any other project WordPress is not perfect. Just like any other project, I agree that WordPress should not be used for everything.

However, not using WordPress because “the code is a mess” is – to put it plainly – a dumb and shortsighted reason. While the core code is a bit of a jumble it is fast and secure. Any code written on top of that to extend the system can be written well.

The trick is to employ professionals, use trustworthy and high-quality products and maintain your website properly. And what platform or any other area of life is that not true in?

Not using WordPress because the code is a mess is a dumb and shortsighted reason. Click to Tweet

Facebook Comments
Spread the love

Posted by News Monkey