Guiltless Code #1 – There’s no “right” way

If you’re just getting started with PHP development, or even looking to increase your skills, a great place to start is PHP: The Right Way.  However, be warned that there is not a “right” way to code in PHP (or any other language, really).  But “PHP: A very good guide to writing code that might be beneficial depending on your specific scenario” doesn’t really have that ring to it.  The fact is, everyone’s situation is unique, and there’s no one way that will be best for every situation.

For an example, let’s start with the ‘Getting Started‘ section: “Use the Current Stable Version (7.1)”.  That’s great advice, and if you have the capabilities and resources that’s what you should do.  But what if you don’t have extra funds to put towards hosting and need to use a free hosting option?  Most of the free PHP hosts I found were still on PHP 5, and only one was using 5.6.  If all you’re able to use is a server with PHP 5.3 on it, I say, “Go for it!”. That’s going to be your “right way”.

As far as developing locally, check out the “All-in-one installers“.  There are plenty of sites and Reddit posts that will tell you how you need to be using vagrant or docker or something, and by all means use them if that interests you.  Just don’t feel like using WAMP or MAMP is somehow “bad” because none of the experts are using them.  The *AMP installers are pretty amazing, and they are super easy to get set up.

Finally, let’s talk about Object Oriented Programming. Over the years, a lot of influential devs have elevated Uncle Bob Martin as the sage of all things TDD, and tangentially OOP.  While he offers good advice, I tend to find his sarcastic writing and speaking style rather dismissive and detrimental to those who are new to programming and trying to get their footing.  Feel free to learn about “single responsibility” and “encapsulation” and other programming jargon usually used about OOP… but also, feel free to write a single php file with a thousand lines of procedural code. Oh, and go ahead and mix in your html, css, and even javascript into that file. Forget the buzzwords, just create something and play around.

Speaking of Uncle Bob, in a later post, we’ll discuss why you can throw your TDD and unit tests out the window.

The point is, the “right way” is totally subjective.  People talk about “best practices” and “anti-patterns”, and apply their judgments to them… but in reality, they’re just suggestions.  Sure, they may be good suggestions, but it’s all just people’s opinions and you shouldn’t feel bad about not following them.

Leave a Reply