Want to learn object-oriented programmming? Get my free course

WordPress core as a gateway to better coding

How many of you got into PHP coding because of WordPress?

– Matt Mullenweg

Me and roughly half the room of 200+ attendees raised their hand to that question. That’s pretty incredible mused Matt. He asked that question while answering the larger question asked by 9th grader Lucas Cherkewski which was “How can WordPress be used in an education context to learn coding?”

I have been involved with WordPress for over half its 10 year existence and while I have gone from simple attendee to volunteer to community organizer over that time. I have always been a bit of the crazy one in terms of trying to help the community code better and learn about more advanced programming topics. That’s because I have been coding since I am 7-8 years old so while I learned PHP through WordPress. I had done plenty of programming before then.

Plugin development is like high school

When I was coding in high school, I couldn’t even do something as cool as a WordPress plugin. The web was just starting. I was mostly coding in Basic doing silly things like a text-based RPGs. So I think it’s amazing that someone can solve small problems with a plugin and share it with the world!

For a lot of people, that’s enough. They can solve small problems without knowing a lot of advanced programming concepts. They don’t need to graduate to college level concepts. WordPress has a lot of great APIs that are easy to use and require no advance programming knowledge.

How do you graduate to college level coding?

I did a WordPress meetup on object-oriented PHP recently and I can’t say that I am the best of teachers and a lot of the utility and reason to use object-oriented programming was lost on most because WordPress doesn’t use a lot of objects yet due to its recent PHP4 heritage.

How do I get better at PHP coding?

I don’t get asked that question a lot, but, a few months ago, Michal Bluma asked me how I got into more advanced PHP coding. I told him definitely not with WordPress. I told him I had done a lot of learning looking at the code base Doctrine1, but version1 of Doctrine is mostly discontinued and Doctrine2 is a different beast entirely.

I told him take a look at Symfony, but that’s akin to someone going from high school to college graduate. The knowledge gap is HUGE. The same would be said about Doctrine2, Zend Framework, etc.

Fundamentally, there’s no way easy way for a WordPress developer close the gap.

WordPress core is an ideal candidate for this

WordPress core would be a great place for people to get a taste for advanced programming knowledge. What’s great is that all the APIs already hide most of the internals so, if someone is looking at the core code, it’s because they want to look at it. There’s an opportunity here to allow them to become better coders! Unfortunately, that opportunity is currently wasted.

Core needs stronger coding standard

I am not talking about syntax here, but actual code quality. Core devs need to raise the bar a bit more. I am not talking about super advanced things like Reflection objects or metadata objects, but just better knowledge and use of object-oriented principles. Learning how to do object-oriented programming is really the next step if you want to learn more.

As an example, last night I submitted a ticket to core about the use of final with the WP_Post class. In my opinion, that should have never made it to core in the first place and shows a fundamental misunderstanding of object-oriented coding especially in an open source environment.

What needs to change

Honestly, it would be good if WordPress core at least used some PHP object-oriented best practices. Here are things that would be great for people looking to learn a bit more about being better PHP programmers:

  • Using interfaces where it makes sense to do so like with WP_Widget and WP_Post for example.
  • Severely limit the use of magic methods especially __get and __set
  • Exception handling instead of the white screen of death
  • Proper variable visibility
  • More abstract classes

This is just to name a few. You can find some of these in the code base already, but new code is still being committed where these basic rules are disregarded which is really the point I am trying to get across.

As a core dev, you should be holding yourself up to higher standards because you are indirectly a teacher for thousands of fledgling PHP developpers.

Feel free to leave a comment below or discuss on Hacker News.

Creative Commons License