PHP Best Practices

You know the worst part about focusing on function over form, and working mostly on your own? You neglect to make sure that your coding style is uniform, that you’re following best practices, and that your code is properly SPACED and INDENTED (one tab per level). A lot of times I don’t have to go back to the code or share it, so it just gets left the way it is – because it works.

I don’t even want to go into how many times I’ve had to go back over my code and space out variables inside of brackets, and move them from being in the function calls themselves to being declared outside of the function call. At the same time, you have to make sure you don’t copy extra variables – that is, instead of copying predefined variables to smaller-named variables, just use the predefined variables to keep memory usage down.

Following DRY princples (Don’t Repeat Yourself) is another one. When I am starting something from scratch, I’m famous for repeating procedures that could be condensed into a single function call, then called multiple times. At least when reviewing after the initial coding spree I will go back and condense and clean up, but it’s still not fun when you get into 1000s of lines of code. We iterate versions and find better ways to do things for a reason, I guess.

Ultimately, it’s up to the coder as to their own particular style, but realistically, if you train yourself to do it ahead of time rather than just powering through an evening getting the project completed and working (I’m guilty) as soon as possible, then you’ll save yourself time in the long run.