Software Engineering in WordPress, PHP, and Backend Development

Category: Articles (Page 116 of 258)

Personal opinions and how-to’s that I’ve written both here and as contributions to other blogs.

Singleton Design Pattern and Dependency Injection, Part 1

The Singleton Design Pattern is something that I’ve talked about before in previous articles.

As Wikipedia so eloquently defines it:

In software engineering, the singleton pattern is a design pattern that restricts the instantiation of a class to one object. This is useful when exactly one object is needed to coordinate actions across the system.

If you’ve done any work with object-oriented programming and familiar design patterns, then it’s likely that you’ve come across it (if you haven’t used it).

Depending on who you ask, the singleton design pattern may be treated as an anti-pattern, like some weird use of a “poor man’s namespace,” or one of the many other negative views of it.

Though these perspectives aren’t necessarily wrong, there are times where it’s okay to use it.

Continue reading

The Reality of Software Development Pressure

I recently heard a quote from someone (and if I could remember who said it, then I’d give attribution – but this is what happens when tweets just happen to scroll on by, right?) that I liked:

Setting deadlines before requirements is like setting a wedding date before you’ve met your partner.

And yes, it’s obviously tongue-in-cheek, but it’s lead me to think a lot about the breakdown that exists between all of the discussion around software best practices, things we should be doing, architectures and patterns we should be following, and then what we’re actually doing and what we’re shipping out to the world.

Development Pressure: Setting Requirements

At this point in my career, I can’t help but wonder if we enjoy talking about and discussing a lot of the things we should be doing as some escape to some of the hacked solutions we end up releasing.

Continue reading

One Step Towards Dependency Injection in WordPress

Dependency Injection is one of those programmer-y terms that sounds far more complicated than it is.

As defined in Wikipedia:

Dependency injection allows a program design to follow the dependency inversion principle. The client delegates to external code (the injector) the responsibility of providing its dependencies.

The client is not allowed to call the injector code. It is the injecting code that constructs the services and calls the client to inject them. This means the client code does not need to know about the injecting code.

But think about it like this (because if you’ve used object-oriented programming, you’ve no doubt done something like this):

  • You have a class, say Class A that maintains a reference to another class, Class B.
  • In the constructor for Class A, we instantiate Class B and set it equal to a property.

Easy enough, right? Here’s the implication:

Class A now has a dependency on Class B and that dependency is only set during the instantiation process in the constructor of Class A.

On a small scale, this isn’t that big of a deal but as a plugin or an application gets more and more complicated, there are all of these dependencies set in the system without any way to necessarily test them in isolation.

And don’t get me wrong: There should be some cohesion among objects in an application, but the degree to which they are coupled should be small. There are a lot of reasons for this many of which are outside the scope of this post.

To help mitigate this, programmers have created all kinds of strategies to make sure that our classes can be small and focused and tested in isolation all the while working with other parts of the system.

And one of the most popular ways to do this is through dependency injection. But what does dependency injection in WordPress look like (and is it any different than in other applications)?

Continue reading

Understanding WordPress Hooks

WordPress hooks are arguably the foundational topic that developers need to learn and understand when it comes to building more advanced functionality for WordPress.

WordPress Hooks

Yes, you can build an entire theme primarily with markup, styles, and JavaScript. Though you may need a few server-side functions in PHP, it’s easy to find things like this in the WordPress Codex or in Underscores.me.

But if you’re someone who’s new to WordPress or who is ready to take the next step regarding extending the platform or writing a plugin, then it’s important to understand to know what WordPress hooks are, how they work, and what they’re designed to do.

And that’s what I’ve covered in my latest series on Envato.

Continue reading

Your Source Code (“This Could Be Better”)

I’d like to think that one of the struggles many developers feel when shipping code is a sense of “this could be better” before they push whatever button to send their code out into the world.

This Could Be Better: Code Review This

Yeah, okay, code review this.

It doesn’t necessarily matter if this is a hobby project, if this is a project for a corporate job, a freelance job, or if this is something that’s for an open source project. I say that because I think this is something that many of us feel with whatever it is that we release.

It’s a feeling of something is “not quite done” or “if I could just refine this a little bit more.” I know: This isn’t the first time I’ve talked about this before, and it’s likely not going to be the last.

And the feeling is not without merit. Other developers can make us feel like we’re doing something wrong (sometimes we are, sometimes we aren’t). But in our industry, I think there’s more of a spectrum of optimal-to-suboptimal. Though some may not agree, a friend of mine recently said it best:

The software industry is too vast and too fast to keep up with it all. But because it’s now that way, people find their niches and think that it’s the “best” or “only” way to get something done.

The further I get into my career, the more I feel this sense of obligation to make things as pristine as possible before sending it to a client, user, or just out for the world to use.

And though I think this is important, it’s important to make sure that I (and we) are doing this for the right reasons.

An example of a wrong reason might go something like this:

It’s not because it doesn’t meet requirements and it’s not because it doesn’t fulfill what was requested by the client. It’s because how others might perceive the work when they do not have the proper context.

So of course, I don’t think there’s anything wrong with wanting to make your code base or your architecture as robust as possible. We should all strive for that. But I believe that it’s important to contextualize appropriately and adequately scope your sprints, milestones, work or however you group your tasks together.

Continue reading

« Older posts Newer posts »

© 2025 Tom McFarlin

Theme by Anders NorenUp ↑