They say that if you aren’t embarrassed by the code you wrote six months ago, you’re doing it wrong. (Or sometimes you hear six weeks, or some other timeframe.)
This is totally true for me. On one hand, it is mortifying to me that potential employers are looking at my code – I want to look over their shoulders and point out all of the things that I know I could improve. On the other hand, I find it immensely gratifying to look at the code I wrote more than a few months ago and to see how far I have come in such a short time. To me, it’s like being an archaeologist and uncovering layers of a city: each layer represents new advances, new knowledge, new technologies. I can look at old code and see just how primitive it is compared to what I am doing now.
So what have I learned since early 2014 when I started to focus on writing plugins? Well, some time around fall of 2014 I carefully read the WordPress PHP coding standards, so the code I wrote after that has Yoda conditionals and spaces inside parentheses. A few months after that, I started really applying DRY principles to my code (my code has gradually been getting DRYer and DRYer since then). In early 2015, I conquered AJAX, and since then I use AJAX a lot.
My early code tends to be very linear – each function goes through a list of actions. In recent months, I have started splitting functions up, so that each function only does one action and calls other functions if it needs to do more than one action.
Some of my code is poorly organized. In some cases, this is because I didn’t anticipate everything that a plugin would need to do, and couldn’t plan for it all in the beginning. In other cases, it is because my ideas about how to organize code have changed. I am now starting to experiment with design patterns, in the hopes of making my code more tidy and functional.
So if you happen to look at my code, keep in mind that you aren’t seeing a polished, finished product – you are seeing the story of my growth as a developer.