单一决策和行动报表的优先风格是什么? [英] What is the prefered style for single decision and action statements?

查看:206
本文介绍了单一决策和行动报表的优先风格是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在支持单一决定和不带括号的动作的语言的情况下,例如以下示例:

In the case of languages that support single decision and action without brackets, such as the following example:

if (var == true)
    doSomething();

写这个的首选方式是什么?是否应该使用括号,或者应该将其使用作为个人开发人员的偏好?此外,这种做法取决于代码块的大小,例如在以下示例中:

What is the preferred way of writing this? Should brackets always be used, or should their usage be left as a preference of the individual developer? Additionally, does this practice depend on the size of the code block, such as in the following example:

if (var == 1)
    doSomething(1);
else if (var > 1 && var < 10)
    doSomething(2);
else
{
    validate(var);
    doSomething(var);
}


推荐答案

正确答案。这是公司内部的编码标准。如果您能在整个公司保持一致,那将很容易阅读。我个人喜欢

There isn't really a right answer. This is what coding standards within the company are for. If you can keep it consistent across the whole company then it will be easy to read. I personally like

if ( a == b)    {
    doSomething();
}
else {
    doSomething();
}

但这是一场圣战。

这篇关于单一决策和行动报表的优先风格是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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