51.2 F
Los Angeles
Sunday, January 29, 2023

Apple March 8, 2022 Event

Apple announced several products during their March 8, 2022, event. Studio Display Mac Studio iPad air iPhone SE iPhone 13 and 13 Pro color addition Some of the products will...

Eastman files motion for exculpatory information and continuance

In response to the January 6 Select Committee Brief to Eastman Privilege Assertions, Eastman has filed a new motion with the court. A request for the court to require...

February 2022 Employment Report

U.S. Bureau of Labor Statistics reported today that total nonfarm payroll employment rose by 678,000. The unemployment rate edged down to 3.8 percent The employment number exceeded forecasts The...

Spacing WordPress Code Adds Readability and Improves Sharability

Tom McFarlin recently wrote a beautiful piece suggesting two tips for writing WordPress code. A few commenters stated they were against spacing as described in the WordPress coding style. Others argued against the tip for writing WordPress code: filter, documentation, and function.

Spacing Improves Readability

The PHP code in a WordPress plugin is not just about the end results but should be written for the novice programmer wanting to learn from your work. This is why spacing may seem like a bad idea until you think about the novice who may read the code.

I’ve spent countless hours reading code written by others and can tell you spacing allows me to view the code easier. Sometimes I print out the code and mark it up with a pen and highlighter. It’s all about interacting with the code to try to dissect and understand why something is written a certain way.

Please consider this analogy: a writer would not put everything into one paragraph, right? Or more extreme, a writer would not crumple up a paper they’ve just authored because someone else may want to read the work. Maybe the point is that the PHP code is not just the result / return values but the code itself.

As a final plea, spacing your code helps others and that is the true spirit of Open Source.

Skip the IDE when Learning

Maybe you are considering the latest version of PHPStorm. This IDE (and many others) can ‘refactor’ your code – and space it out to meet the coding standards. This is a bad idea. Why? Sometimes spacing out can help you find an error before the problem becomes hidden.

Still I appreciate the time it takes to write clean code and have recently “scribbled” out ideas and later cleaned things up so I could evaluate the ideas. In fact, I recently found a problem in my reasoning in a block of code after I was adding space to step back and view the code.

These two reasons are why I spend hours going through past lines of code and seeing if there is a better way. Sometimes an error jumps out of the page.

What do you think? Should authors of WordPress plugins consider the novice programmer or only consider the end result of the plugin?

Related Stories

Exit mobile version