为什么我应该总是使用尽可能多的方括号/大括号,即使使用更少的方括号也可以吗?

问题描述 投票:1回答:1

[我经常看到专业程序员,在我通常会插入的地方省略括号,例如:

if(i==1)
printf("Hello World!");           // the if-body is not enclosed by curly-brackets.

x = 4 * 6 + 7 * 2;           // I would brace (4 * 6) and (7 * 2), not (6 + 7) which would lead 
                             // to a different result.

[我的学习书和老师告诉我,总是在应使用的地方加上方括号(即使仅用于[if]表达式,例如if(i==1){printf("Hello World!");})。

标准对如何正确编程或什么是好的编程风格没有太多要求。

但是如果专业程序员在有效的地方忽略了他们,那我为什么要这么做呢?

c++ c syntax brackets curly-braces
1个回答
0
投票

因为我不会浪费时间阅读否则。

© www.soinside.com 2019 - 2024. All rights reserved.