This entry is part 8 of 9 in the Plugin Thoughts Series
- Plugin Thoughts Episode 1: Making Your Plugins More Extensible
- Plugin Thoughts Episode Two – Use Filters for Plugin Text
- Plugin Thoughts Episode 3 – Don’t Forget About Core Functions
- Plugin Thoughts Episode 4 – Learn How Core Does It
- Plugin Thoughts Episode 5 – Take Responsibility for Your Products
- Plugin Thoughts Episode 6 – Contribute to the WordPress Codex
- Plugin Thoughts Episode 7 – Remember Core CSS
- Plugin Thoughts Episode 8 – Create Clean Code
- Plugin Thoughts Episode 9 – Write Better Code; Release Better Plugins
In Episode 8 of Plugin Thoughts, I discuss some of the benefits of creating clean, readable code, and some of the downsides to writing poorly formatted and unreadable code. Whether you build plugins or themes, CSS, HTML, Javascript, or PHP, this applies to you.
At times I am surprised by the poor quality of code that I see laying around in WordPress plugins and themes, and I don’t just mean poorly written (in terms of efficiency and functionality). In this case, I am specifically referring to the quality of code formatting.
You do not have to be a master developer to create clean code, you only need to know how to use the space bar, tab key, and the return key. It does not take more than a moment to properly format your code (including indention), but it will literally save you hours (on large projects) when you have to look back over your project.
Which do you think is easier? Finding a bug in code that is extremely poorly formatted, possibly including poor file / function names, or finding a bug in code that is clean, well laid out, and formatted properly? Unless you live in a very backwards world, you will of course find the second scenario easier to debug.
Have a listen to the episode below.
Great topic. I hope all coders learn the importance of meticulously — and consistently — formatted code early in their careers. This is what separates the hacks from the pros.
Thanks for stopping by Brian. I constantly find poorly formatted code, even from good developers, and there is just no good reason to NOT format it well.
I completely agree! It’s hard to understand how you still can have fun when writing messy code. Unfortunately, I too am surprised by the amount of poorly formatted code in many WordPress plugins and themes. A consistent and clean coding style is lacking in most of the plugins I played around with. Moreover, they are often generating PHP notices for undefined indexes and stuff. Some kind of quality control for plugins hosted on the WordPress repository would be very welcome.
I’m guilty of writing sloppy code… a lot. I know it only takes extra seconds to make it all nice and pretty… I guess it’s a laziness thing…
Indeed. i HATE looking through my own sloppy code…. It’s usually when I am going through it to fix something, that I take the time to format it a little better =D