使用逗号来防止需要大括号 [英] Using comma to prevent the need for brace pair

查看:174
本文介绍了使用逗号来防止需要大括号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有时,当我有一个多用例如果或一个非常简单的,只有两个语句,我将放弃大括号,而是使用逗号。这是一个坏的利用的功能,是丑陋和坏的形式?

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆