Читать книгу Professional WordPress Plugin Development - Brad Williams - Страница 63
Indentation
ОглавлениеPut 10 programmers in a room and pose the question, “Spaces or tabs?” This may be the closest you'll ever see to a programming discussion resulting in fisticuffs. Many a developer has lived and died on their personal space/tab hill. The one thing that most can agree on is that your code should follow some sort of standard indentation.
The WordPress standard is to indent all code with tabs. Consider the following example of an if/else statement:
<?php if ( $condition ) { echo 'Yes'; } else { echo 'No'; }
It's hard to follow the logical structure of the code with no indentation. Instead, you should indent each line within the brackets of the conditions, as shown in the following example:
<?php if ( $condition ) { echo 'Yes'; } else { echo 'No'; }
The one exception that WordPress makes to its tab preference is when aligning multiple lines of similar items. Take note of the spacing usage in the following snippet:
<?php $some_var = 'ABC'; $another_var = 'JKL'; $yet_another_var = 'XYZ';
As you can see, the operators and values assigned to the variables are clearly lined up and easy to read.