So let’s talk about coupling! Coupling is a complicated problem because you can never get rid of it completely. All that you can do is control how much it spreads. And there’s more than one way to do that.
One of these ways is the dependency inversion principle. It’s one of the most important principles in object-oriented design. And it’s why it’s part of the famous SOLID design principles. (It’s the “D” in SOLID.)
The dependency inversion principle isn’t something that you see with WordPress. That’s because most WordPress developers don’t use object-oriented programming. (But it’s always a good time to start if you’re not using it!) And the dependency inversion principle only helps when you’ve been using it for a while.
But what makes the dependency inversion principle special? Why is it such almost a mandatory aspect of object-oriented design? These are good questions that you deserve an answer to.
Continue reading Dependency inversion principle and WordPress
I gave an introduction to automated WordPress deployments at WordCamp Miami 2017. This is the companion article that I wrote for it. If you’re just looking for the slides, click here.
How do you feel when you have to update the code on a client’s WordPress site? Do you feel confident that everything will be ok? Or are you filled with dread as if you were about to play a round of Russian roulette?
For a lot of us, it’s a lot closer to the Russian roulette! We press the upload button of our favourite FTP client. We then spend the next minute refreshing the home page in our browser hoping not to see a white screen of death. (Followed by a sigh of relief when everything loads as it should!)
This is a pretty stressful way to work. You shouldn’t have to feel this way each time that you want to update the code of a WordPress site. It should be something that you can do as often as you want without worrying that you broke your site in the process.
And that’s where the idea of automated WordPress deployment comes in. As the name implies, it’s all about automating this process of updating a WordPress site. This, in turn, makes this risky process safer. (But keep in mind that this isn’t a bulletproof solution!)
Gone are the days where you’re playing Russian roulette each time that you want to make a change! You can now update your client’s WordPress site with a lot more confidence. This lets you focus on shipping bug fixes (yay bugs!) and new features.
That said, there are a lot of different ways of automating your WordPress deployments. We’ll go over what makes a successful automated WordPress deployment workflow. We’ll also look at a lot of different tools that you can use to achieve it.
Continue reading Introduction to automated WordPress deployments
I spoke at WordCamp Atlanta 2017 on how you could use teaching as a learning tool. This is the companion article that I wrote for it. If you’re just looking for the slides, click here.
As WordPress developers (or developers in general), we’re always looking to improve our skills. We read blog posts, watch screencasts, listen to talks at WordCamps and so on. These are all great ways to learn new things.
But there’s one way to hone your programming skills that doesn’t get as much attention as it should. It’s “learning by teaching“. Teaching is a great way to improve your skills as a developer.
Now, you might be wondering, “Seriously, how can teaching make me a better developer?” People don’t tend to associate teaching with skill building. After all, how could you teach something if you didn’t know it already?
That’s a good question! It does feel like this shouldn’t be able to work. But it does! And that’s why it’s worth taking a better look at this idea of “learning by teaching”.
Continue reading How to use teaching as a learning tool
So this is another article that I’m doing for myself and also to be transparent. I don’t change my computer often (My old computer was a mid-2011 MacBook Air!) and I usually use the opportunity to review my workflow. This time around I wanted to document the process in some way.
The initial plan was to do something like this. That said, a few people told me that it would be something useful to write down. So this is what this article is going to be about.
Since everything is still quite fresh, I can walk through my thought process. I think it’s useful when you’re trying to make decisions whether this tool is useful for you or not. We don’t all work the same way so my workflow might not fit yours.
It’s also worth pointing out that this is going to be macOS centric. I haven’t developed on another operating system in a long time. So you might not get as much out of this if you’re using Windows or Linux.
Alright, so you have your new MacBook Pro box in front of you! You’re ready to get going. You unbox it, boot it up, set up your account for the first time and get to the desktop screen. What’s next!?
Continue reading How I setup my 2016 MacBook Pro
A concept that comes up a lot while doing object-oriented design is coupling. We use it to describe how connected the different parts of your code are to one another. But, even explained like that, the concept of coupling can still be a hard to grasp.
On top of that, we often pair it with another concept called cohesion. We use cohesion to describe how well the different parts of your code fit together. This tells us whether everything was well-designed or not.
In fact, this is why coupling and cohesion are so important. There’s a strong relationship between them and the quality of your code. Code that doesn’t have any major coupling or cohesion problem is more often of higher quality. It’s more maintainable, reusable and less prone to problems.
That’s why you want to keep these two concepts in the back of your mind when programming. But that’s easier said than done when these concepts aren’t well understood. That’s why we’ll demystify them today.
Continue reading Coupling and cohesion in WordPress and beyond
Well, we’re almost done with 2016! Around the same time last year, I did my first year in review. (In reality, it was more of a 2012-2015 review!) I want to continue this trend by doing a review of this year.
It’s a way for me to be transparent about what I’m doing. It’s not something that I’m good at. (The most common question I get is still “What do I do?”) It also lets me document what I’m doing to see if I’m making progress towards where I wanted to go the year before.
This means that this article is more for me than for you. That said, I think there’s a lot of value in reading how people are navigating the complex game of life. (Not that game of life!) That’s why I like reading them!
Continue reading 2016 in review: #Carl2016
This site has a lot of object-oriented programming articles. Most of them focus on solving WordPress problems using object-oriented programming. This is great when you’re comfortable with object-oriented programming.
But most WordPress developers aren’t that comfortable with it. (You’d think there’d be a book on that or something.) It’s one thing to read about basic concepts like encapsulation and inheritance. It’s another to put them in practice. There are a lot of obstacles that you have to overcome.
One of these obstacles is the proper use of the static keyword. Static methods are a great object-oriented tool to use. But, like all good things, we can also abuse it if we’re not careful.
This happens a lot more in the WordPress development world than anywhere else. And there are good reasons for that. We’ll look at why that is and what you can do about it.
Continue reading How to use the static keyword with WordPress
No set of control structures is more pervasive in programming than
else. With a few exceptions, you’ll use at least one per function or method that you write. There’s just no way around it.
But conditionals (that’s what we call these control structures) fit in the “easy to learn, hard to master” category. In fact, they’re so easy to use that you can develop some bad habits around them. (This is also a problem with loops.) This can lead to code that’s complex and hard to read or even test.
That said, it’s possible to develop good programming habits with conditionals. This is what this article will try to help you with. We’ll go over some programming techniques that can help make conditionals more manageable.
Continue reading Mastering the use of PHP conditionals
Being a plugin developer isn’t easy. You have to get your plugin to work with WordPress. But more often than not, you also need it to interact with other plugins.
This interaction can take various forms. For example, you might need to modify another plugin’s behaviour using the plugin API. Or you might want to help customers migrate away from another plugin (or product) to yours.
This second scenario is the one that we’re going to look at in this article. It’s a good opportunity to introduce a new software design pattern. We call it the strategy pattern.
Continue reading Importing data into WordPress using the strategy pattern
Alright, it’s time to continue our journey building our awesome
WP_Query_Builder class! So far, we’ve only designed it to build simple WordPress queries. But not all WordPress queries are simple or easy to model using just a cascading method.
It’s even possible that you’ve run into the limits of the
WP_Query_Builder already. The class that we created then wasn’t a complete solution. It had some serious limitations if you were a
WP_Query expert. You couldn’t use it to perform complex WordPress queries.
What do we mean by complex WordPress queries? We mean queries that use a complex
WP_Query query parameters. At the moment, there are three of them:
So, for this article, we’re going to back to our
WP_Query_Builder class. We’ll add support for one of these complex
WP_Query query parameters. We won’t go over all three due to how complex they are. But you can apply what you’ve seen for this one query parameter to design a fluent interface for the other two.
Continue reading Designing a class to create complex WordPress queries