読者です 読者をやめる 読者になる 読者になる

てきとうなメモ

本の感想とか技術メモとか

コーディング規約におけるif文の中括弧

Programming C++ C Java PHP

世の中のコーディング規約的にはどうなのかなと思ったのでちょっと調べたら中括弧付ける方が多い気がする。

C or C++

Google

In general, curly braces are not required for single-line statements, but they are allowed if you like them; conditional or loop statements with complex conditions or statements may be more readable with curly braces. Some projects require that an if must always always have an accompanying brace.

Google C++ Style Guide

括弧なしOK

High Integrity C++ Coding Standard

Follow each control flow primitive (if, else, while, for, do and switch) by a block enclosed by braces, even if the block is empty or contains only one line. Use of null statements or statement expressions in these contexts reduces code readability and making it harder to maintain.

6.1.1 Enclose the body of a selection or an iteration statement in a compound statement | High Integrity C++ Coding Standard

括弧必須

CERT C++ Secure Coding Standard

Opening and closing braces for if, for, and while statements should always be used even if the statement's body contains only a single statement.

EXP19-C. Use braces for the body of an if, for, or while statement - Secure Coding - CERT Secure Coding Standards

括弧必須

Applied Informatics

The placement of braces seems to have been the subject of the greatest
debate concerning the appearance of both C and C++ code. We recommend
a style that, in our opinion, gives the most readable code. Other styles may
well provide more compact code.

www.appinf.com/download/CppCodingStyleGuide.pdf

表現が微妙。多分、括弧推奨

Possibility

All if, while and do statements must either have braces or be on a single line.

C++ Coding Standard

括弧必須

JOINT STRIKE FIGHTER AIR VEHICLE

AV Rule 59 (MISRA Rule 59, Revised)
The statements forming the body of an if, else if, else, while, do…while or for statement shall
always be enclosed in braces, even if the braces form an empty block.

www.stroustrup.com/JSF-AV-rules.pdf

括弧必須

Uwyn

Always Uses Braces Form, even if there is only a single statement within the braces.

Uwyn - C++ coding standard - Braces Usage

括弧必須

Java

Oracle

Note: if statements always use braces, {}. Avoid the following error-prone form:

Code Conventions for the Java Programming Language: 7. Statements

括弧必須

Google

4.1.1 Braces are used where optional

Braces are used with if, else, for, do and while statements, even when the body is empty or contains only a single statement.

Google Java Style

括弧必須

Douglas Crockford

Braces are used around all statements, even single statements, when they are part of a
control structure, such as a if-else or for statement. This makes it easier to add
statements without accidentally introducing bugs due to forgetting to add braces.

javascript.crockford.com/javacodeconventions.pdf

括弧必須

PHP

PSR-2

The body of each structure MUST be enclosed by braces. This standardizes how the structures look, and reduces the likelihood of introducing errors as new lines get added to the body.

PSR-2 — Coding Style Guide

括弧必須

PEAR

You are strongly encouraged to always use curly braces even in situations where they are technically optional. Having them increases readability and decreases the likelihood of logic errors being introduced when new lines are added.

Manual :: Control Structures

括弧推奨

Symphony

Use braces to indicate control structure body regardless of the number of statements it contains;

Coding Standards (Contributing to Symfony)

括弧必須

Zend Framework

PHP allows statements to be written without braces in some circumstances. This coding standard makes no differentiation- all "if", "elseif" or "else" statements must use braces.

Coding Style - Zend Framework Coding Standard for PHP - Zend Framework

括弧必須

WordPress

Braces should always be used, even when they are not required:

WordPress › PHP Coding Standards « Make WordPress Core

括弧必須