Author Archives: Brian

Photo by Clem Onojeghuo on Unsplash
Applying The Craft

In a previous post I talked about learning more about the core of PHP, specifically the ArrayIterator class. I’ve been reading about it and I found a situation in which to apply what I’ve learned. I have a client that is using WordPress and a previous developer of theirs created a custom plugin, but didn’t always store the data in a consistent manner. At first I noticed it with dates, some were in the form of YYYY-MM-DD and others were in DD/MM/YYYY, and other places a Unix timestamp was used. I have my opinions about which one to use and why, but what really confused me was having them as different formats even in the same table. Instead of using a MySQL DATE, DATETIME, or TIMESTAMP field type, it is all intermixed.

However, the bright side of this situation: I have the possibility of slowly shifting some functionality out of their current CMS into a custom API that I will be building for my client. The reason this is a good thing in my view is that it allows me to import this data into a second database and normalize it as I go. Which is where the ArrayIterator will come in to play. I plan to use it with local copies of the code and database to see how effective it is as I parse the records and determine how the dates are stored and what to do with them. Maybe this isn’t the best use of it, but it is an opportunity to use it in a real world situation and apply what I’ve learned. Maybe I’ll find it isn’t the best tool for the job, or I may find that it helps keep things sane and it is worth the effort.

Becoming A Craftsman

It was recently brought back to my attention about a BBC mini-series called “Mastercrafts”. It followed three people in each episode that wanted to become an apprentice to a master of a trade. Something that stuck out about each episode to me is that they always spent time in the environment of their trade. They didn’t have classes, take tests, research things from books, or in any other way avoid beginning to practice the basics of the trade. There was time spent instructing the students, but it was also quite hands-on. That is something I’ve always found to be best for me. I like to get in and work directly with something, in my particular case programming. In a lot of ways, I was able to transfer ideas that the master was using to help train the students from their trade to mine. I have no mater to assist me, but I won’t let that stop me.

The first episode was woodworking, and they spent time in a small forest/woodland area. They had a lathe that they had to power using a pedal. They had to get the basics of being able to keep a steady rhythm with their foot, balance on their other foot, and keep their hands steady as they carefully shaped the piece of wood they were working on. Thankfully I don’t have quite the same level of physical fitness required for what I do, but it did make me think about how they don’t just shape the wood with a tool in their hand, they shape it with their whole body. If their rhythm is off, if the speed isn’t consistent and fast enough without being too fast, the wood could be ruined quickly and they will have to start again. They have to be in it with their entire body and mind. I want to approach programming that way.

I have realized my knowledge of the basics of PHP isn’t consistent, I know some things well, but others are lacking. I’ve spent a lot of time in frameworks because they do a lot of the heavy lifting to let me actually produce and ship things, but I don’t know how they handle things underneath the surface. I don’t think this is required knowledge to be able to do what I do, but I think I’m past the point where I should begin to understand the language itself to better be able to solve problems.

To do this I need a starting point. I have no one to look to, I have no path that is set before me. I could stumble around in the documentation trying to figure out in what order this knowledge needs to be processed in. But a mindful approach will save me time and energy. So I have been going through my projects and looking at what are the common things that I do? What are the top five problems I tend to encounter, and how am I solving them? What is painful about my solution, how can I improve it? Is it unwieldy, unreadable, feels too complex for the problem it solves? The most common thing I have found that I do is iterating over an array of other arrays or objects. That’s where I’m going to focus first. Learn PHP’s internals for handling arrays, objects, and what functions or classes it provides for doing so. I have found in the past that there is a myriad of array functions that can be useful. But what about the ArrayIterator class? Or other iterators? That is my first personal lesson. I plan to read through the documentation and then create a blog post that explains what I’ve found and how I’ve used them instead of doing for or foreach loops.