Home > Backend Development > PHP Tutorial > PHP coding standards (25)_PHP tutorial

PHP coding standards (25)_PHP tutorial

WBOY
Release: 2016-07-13 17:20:29
Original
778 people have browsed it

9.3 Braces

Of the three main brace placement rules, two are acceptable, the first of which is the best:
Place braces in the same column below the keyword:
if (condition)
{
 ...

 while (condition)
 {
 ...
 }
}
Traditional UNIX brackets The rule is that the first bracket is in the same column as the keyword, and the last bracket is in the same column as the keyword:
if (condition) {

 ...

 while (condition) {

  ...

 }
}
Non-principled issues that cause intense debate can be solved through compromise. Either method is acceptable, but for most people I prefer the first one. The reason is something in the field of psychological research and study.
There are more reasons to prefer the first one. If the character editor you use supports bracket matching (such as vi), the most important thing is to have a good style. Why? We say that when you have a large program and want to know where this large program ends. You first move to the opening bracket, and after pressing the button the editor will find the corresponding closing bracket, for example:

if (veryLongCondition && secondVeryLongCondition)
{
 ...
}
else if (...)
{
 ...
}
To move from one block to another just use the cursor to match your bracket keys , no need to find matching parentheses.


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/532579.htmlTechArticle9.3 Braces Among the three main brace placement rules, two are acceptable, as follows The first is the best: place the braces in the same column below the keyword: if (c...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template