DEV Community

Cover image for Good Code in WordPress. Why should I care?
Lucas Bustamante
Lucas Bustamante

Posted on • Updated on

Good Code in WordPress. Why should I care?

About the cover: In this photo, legendary Ballet Dancer & Choreographer Arthur Mitchell performs with the precision of a lifetime dedicated to its craft, with love, passion, training, and dedication, similarly to those who strive to write Good code, which is an art, in its own way.

Software is a young industry and we're still learning how to do it properly. The world evolved very fast in the last couple of decades, boosted underneath by software, so we were able to achieve efficiency at it, but at the cost of a lot of suffering to learn precious lessons.

The guys that were on the tip of the spear of this movement, such as the guys from ThoughtWorks (which are getting old by now, in their 60's), have written books that sum up decades of invaluable, raw, new experience on the challenges of software, and how to overcome it.

What I've learned from reading some of these books from different people is that, when the software is expected to achieve a certain level of complexity, you need to apply methodologies and discipline on the development, otherwise you end up with something that's very hard to understand and eventually impossible to maintain. You save up on development but spend a lot maintaining and have a high cost at adding new features, up to a point where you have to throw it all over and start again, often repeating the cycle.

So we know we need to write good code, but how can we do that?

Writing good code in WordPress is completely feasible. Our problem today is no longer technical, but cultural.

When people talk about SOLID principles and automated tests, we think of a gigantic enterprise with an unlimited budget and an endless deadline, building complex and over-engineered software.

I say from my personal experience that it does not have to be like that. Once you start diving into really high-end OOP, SOLID, and Testing, you can do it naturally. Even though I'm a profound admirer of the philosophy that "Simplicity is the ultimate sophistication", there's a huge difference between achieving simplicity and being simplistic.

Not many developers are willing to dive into such depths to achieve that level of craftsmanship, though. And those who have the nature for that, are often buried into tight deadlines that end up being counter-productive for the company for the reasons stated above. A company can get away with one or two products with bad code, but if that's a habit, it won't sustain itself on the market once the bugs start popping up, developers start to leave, features became ever harder to build.

So, how to actually achieve it, then?

First, some very practical tips for a company is to put in place some kind of internal program for personal growth, with incentives to buy books and courses, and actively suggesting must-read software books for developers and maybe even rewarding them for reading those. It's great for the company, after all.

For developers, I'd like to point out a few useful resources:

  • Use PSR-4 (Yes, you can)
  • Learn what a Dependency Injection Container is. There's a great DI container built by Luca Tumedei, who is my mentor and friend and is specially built with WordPress in mind:
  • Read software books. They are a great source of knowledge because they explain very thoroughly and linearly complex ideas. A couple of books that I personally recommend are: Timeless Laws of Software Development, Design Patterns (by Head First), Mastering the SPL Library. And learn Laravel if you can, it's a good source of inspiration.
  • At some point, learn to write tests. Writing tests for WordPress can be a PITA, but if you persist and break all the barriers you will encounter (because WordPress is hard to test), once you acquire this skill it's something that will change your development life forever. I'd recommend wp-browser for this task, also by Luca Tumedei:
  • But the most important, if you care for your craft, keep pursuing your own improvement and aim high.

If the WordPress community strives to push forward that we are committed to good, clean code. Perhaps in a couple of years, we can attract many great programming talents, and we can focus on building cool stuff and new features and enjoying it, instead of banging our heads against bugs and tangled code!

Top comments (0)