Sometimes I look back over my blog and realize how much I have grown. I had some pretty strong opinions about some coding practices filled with the logic of the time. Sometime I make an assumption about a new feature in PHP and think, “Well, that’s silly”. Turns out I’m not always right (surprise, surprise).
Two posts in particular I would like to make a humble retractions:
At the time I thought I knew something the rest of the industry did not. I was somehow secretly superior. Turns out I was just being stubborn. I was forced to use both code styles for more than a year in my day job.
- Why I Avoid PHP Short Array Syntax
Now that I am used to short array syntax I much prefer it. Plus it keeps inline with other languages which adds consistency.
2. Inject This
I had the opportunity to rebuild one of my project frameworks for a client project. I rebuilt the framework using all of the principles I spoke about in the mentioned posts. I completed the project, felling pretty good about myself. A month later I was tasked to go back into the project and make some changes.
I became immediately frustrated. Why was is so hard to find things? Why was it so hard to change things? I just want to change one value used throughout the app, why do I have to refactor a bunch of stuff?
That is when it dawned on me. Had I used dependency injection this would be so much easier to adjust. I was frustrated because I had followed my own pattern. I proceeded to rebuilt my framework to a complete dependency injection structure. So much better! Now if only I can find a why to do this and maintain performance with PHP 5.2.
I still believe that you can simply use WP actions and filters to achieve dependency injection just fine without an actual container. Personally I much prefer using a container because it feels cleaner and it’s easier to track dependencies.