Coding standards are incredibly important in the WordPress community – they keep everything organized and usable, and more importantly, they ensure that any developer can pick up where another developer left off, or tweak someone else’s code. However, pretty much all developers have unique style of writing the code and tricks up their sleeves to write code faster, which can be a real problem if this affects the quality of the code. Today we’ll go through some of the best practices in PHP development that developers often overlook or deliberately choose to ignore.
Enable Error Reporting
PHP Development often includes countless hours spent over a keyboard with a cup of strong black coffee, and only naturally, mistakes happen. This is why error reporting is incredibly important, as not all errors will actually stop your application from working. While there are different levels of errors, E_ALL will report most errors, whether they’re critical or just warnings, except of level E_STRICT.
Keep in mind that other developers might end up working with your code, either checking it for bugs, or tweaking it and implementing new features, which is why you want to ensure the code is readable and well organized. Use plenty of white space and line indentation to improve readability. You can also tier your code – organize logical chunks of code together into different parts. It’s not just to make the code “pretty,” it will also boost usability and your productivity. In addition to these two simple tricks, you should also make sure you comment the code – you’ll thank yourself down the road when you go back and look for something in the code, or if you just can’t remember what a specific function did.
Naming In PHP Development
Naming is in incredibly underestimated in the world of PHP development. Make sure you follow meaningful, consistent naming conventions with your classes and functions. It’s not just for your own good – there’s nothing worse than going through other developer’s code and trying to figure out the cryptic abbreviations they used instead of names. Try and stick to English words, and follow the Camel naming convention.
While there are many other tips, tricks, and best practices when it comes to PHP development, after going through countless lines of code, we’ve realized that these three are the ones developers overlook most often, making their life, as well as the lives of other developers harder than they should be.