使用逗号来防止需要大括号 [英] Using comma to prevent the need for brace pair
问题描述
有时,当我有一个多用例如果
或一个非常简单的为
,只有两个语句,我将放弃大括号,而是使用逗号。这是一个坏的利用的功能,是丑陋和坏的形式?
Sometimes, when I have a multi-case if
, or a very simple for
, with only two statements, I will forgo braces, instead using the comma. Is this a bad exploitation of the feature, and is it ugly and bad form? Or is it an acceptable way to save time and space?
例如:
if (something)
b = y, c = z--;
而不是
if (something) {
b = y;
c = z--;
}
推荐答案
使用大多数类似C语言的语法功能。
It's indeed a clever way to use that syntactic feature of most C-like languages.
我个人认为,当我编码时,我尽量保持尽可能不模糊始终在所有如果
语句中包含 {和
}
。它可以节省时间,但我更喜欢 clear :它不会加快或减慢代码执行速度。
Personally, I try to stay the least ambiguous as possible when I code, so I always include {
and }
in all of my if
statements. It may save time, but I prefer clarity: it doesn't speed up or slow down the code execution.
这篇关于使用逗号来防止需要大括号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!