强制使用牙套

发布于 2024-08-15 06:20:37 字数 440 浏览 5 评论 0原文

作为我不久前写的代码标准文档的一部分,我强制要求“您必须始终对循环和/或条件代码块使用大括号,即使(特别是)它们只有一行。”

示例:

// this is wrong
if (foo) 
    //bar
else 
    //baz
while (stuff)
    //things

// This is right.
if (foo) {
    // bar
} else {
    // baz
}
while (things) {
    // stuff
}

当您没有用大括号括住单行,然后有人将其注释掉时,您就有麻烦了。如果您不使用单行大括号,并且缩进在其他人的机器上显示不一样......您就有麻烦了。

那么问题来了:是否有充分的理由解释为什么这是一个错误或不合理的标准?关于它已经有一些讨论,但没有人能给我提供比“感觉丑陋”更好的反驳。

As part of a code standards document I wrote awhile back, I enforce "you must always use braces for loops and/or conditional code blocks, even (especially) if they're only one line."

Example:

// this is wrong
if (foo) 
    //bar
else 
    //baz
while (stuff)
    //things

// This is right.
if (foo) {
    // bar
} else {
    // baz
}
while (things) {
    // stuff
}

When you don't brace a single-line, and then someone comments it out, you're in trouble. If you don't brace a single-line, and the indentation doesn't display the same on someone else's machine... you're in trouble.

So, question: are there good reasons why this would be a mistaken or otherwise unreasonable standard? There's been some discussion on it, but no one can offer me a better counterargument than "it feels ugly".

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(21

剪不断理还乱 2024-08-22 06:20:37

我能提供的最好的反驳论点是,空间占用的额外行会减少您一次可以看到的代码量,而您一次可以看到的代码量是影响易用性的一个重要因素。是为了发现错误。我同意你给出的包含大括号的原因,但是在 C++ 的许多年里,我只能想到一次我因此犯了一个错误,而且是在一个我没有充分理由跳过大括号的地方反正。不幸的是,我无法告诉您这些额外的代码行在实践中是否有帮助。

我可能更有偏见,因为我喜欢在相同缩进级别匹配大括号的对称性(以及将包含的语句隐式分组为一个执行块) - 这意味着所有都添加大括号向项目添加了很多行。

The best counter argument I can offer is that the extra line(s) taken up by the space reduce the amount of code you can see at one time, and the amount of code you can see at one time is a big factor in how easy it is to spot errors. I agree with the reasons you've given for including braces, but in many years of C++ I can only think of one occasion when I made a mistake as a result and it was in a place where I had no good reason for skipping the braces anyway. Unfortunately I couldn't tell you if seeing those extra lines of code ever helped in practice or not.

I'm perhaps more biased because I like the symmetry of matching braces at the same indentation level (and the implied grouping of the contained statements as one block of execution) - which means that adding braces all the time adds a lot of lines to the project.

懷念過去 2024-08-22 06:20:37

我在一定程度上强制执行这一点,但对于计算结果为返回或继续循环的 if 语句有一些小例外。

所以,按照我的标准,这是正确的:

if(true) continue;

As is this

if(true) return;

但规则是它要么是 return 要么是 continue,并且都在同一行上。否则,一切都要做好准备。

这样做的原因是为了有一个标准的方法,也是为了避免你提到的评论问题。

I enforce this to a point, with minor exceptions for if statements which evaluate to either return or to continue a loop.

So, this is correct by my standard:

if(true) continue;

As is this

if(true) return;

But the rule is that it is either a return or continue, and it is all on the same line. Otherwise, braces for everything.

The reasoning is both for the sake of having a standard way of doing it, and to avoid the commenting problem you mentioned.

单挑你×的.吻 2024-08-22 06:20:37

我认为这条规则太过分了。严酷的标准并不能造就优秀的程序员,它们只是降低了懒虫搞砸的可能性。

您给出的示例是有效的,但它们有比强制大括号更好的解决方案:

当你没有用大括号括住单行,然后有人将其注释掉时,你就有麻烦了。

有两种做法可以更好地解决这个问题,选一种:

1) 用单行注释掉单行之前的 ifwhile 等。 即像任何其他多行语句一样对待

if(foo)
    bar();

(例如,多行赋值或多行函数调用):

//if(foo)
//    bar();

2) 在 // 前面加上 ;

if(foo)
;//    bar();

如果你没有用大括号括住单行,并且缩进在其他人的机器上显示不一样......你就有麻烦了。

不,你不是;代码的工作原理相同,但更难阅读。修复你的缩进。选择制表符或空格并坚持使用。 不要混合制表符和空格进行缩进。许多文本编辑器会自动为您修复此问题。

编写一些 Python 代码。这至少可以纠正一些不良的缩进习惯。

另外,像 } else { 这样的结构对我来说看起来就像是网络黑客版本的 TIE 战斗机。

是否有充分的理由说明为什么这是一个错误或不合理的标准?关于它已经有一些讨论,但没有人能给我提供比“感觉丑陋”更好的反驳。

多余的大括号(和括号)会造成视觉混乱。视觉混乱使代码更难阅读。代码越难阅读,就越容易隐藏错误。

int x = 0;
while(x < 10);
{
    printf("Count: %d\n", ++x);
}

强制大括号无助于发现上述代码中的错误。

PS:我是“每条规则都应该说明原因”学派的订阅者,或者正如达赖喇嘛所说,“了解规则,以便你可以正确地打破它们。”

I see this rule as overkill. Draconian standards don't make good programmers, they just decrease the odds that a slob is going to make a mess.

The examples you give are valid, but they have better solutions than forcing braces:

When you don't brace a single-line, and then someone comments it out, you're in trouble.

Two practices solve this better, pick one:

1) Comment out the if, while, etc. before the one-liner with the one-liner. I.e. treat

if(foo)
    bar();

like any other multi-line statement (e.g. an assignment with multiple lines, or a multiple-line function call):

//if(foo)
//    bar();

2) Prefix the // with a ;:

if(foo)
;//    bar();

If you don't brace a single-line, and the indentation doesn't display the same on someone else's machine... you're in trouble.

No, you're not; the code works the same but it's harder to read. Fix your indentation. Pick tabs or spaces and stick with them. Do not mix tabs and spaces for indentation. Many text editors will automatically fix this for you.

Write some Python code. That will fix at least some bad indentation habits.

Also, structures like } else { look like a nethack version of a TIE fighter to me.

are there good reasons why this would be a mistaken or otherwise unreasonable standard? There's been some discussion on it, but no one can offer me a better counterargument than "it feels ugly".

Redundant braces (and parentheses) are visual clutter. Visual clutter makes code harder to read. The harder code is to read, the easier it is to hide bugs.

int x = 0;
while(x < 10);
{
    printf("Count: %d\n", ++x);
}

Forcing braces doesn't help find the bug in the above code.

P.S. I'm a subscriber to the "every rule should say why" school, or as the Dalai Lama put it, "Know the rules so that you may properly break them."

无远思近则忧 2024-08-22 06:20:37

我还没有找到任何人提出不总是使用花括号的充分理由。

这些好处远远超过了我听过的任何“感觉丑陋”的理由。

编码标准的存在是为了使代码更易于阅读并减少错误。

这是一个真正能带来回报的标准。

I have yet to have anyone come up with a good reason not to always use curly braces.

The benefits far exceed any "it feels ugly" reason I've heard.

Coding standard exist to make code easier to read and reduce errors.

This is one standard that truly pays off.

日记撕了你也走了 2024-08-22 06:20:37

我发现很难与减少错误并使代码更具可读性的编码标准争论。有些人一开始可能会觉得很难看,但我认为这是一个完全有效的实施规则。

I find it hard to argue with coding standards that reduce errors and make the code more readable. It may feel ugly to some people at first, but I think it's a perfectly valid rule to implement.

ゃ懵逼小萝莉 2024-08-22 06:20:37

我的立场是大括号应该根据缩进匹配。

// This is right.
if (foo) 
{
    // bar
}
else 
{
    // baz
}

while (things) 
{
    // stuff
}

就您的两个示例而言,我认为您的示例的可读性稍差,因为找到匹配的右括号可能很困难,但在缩进不正确的情况下更具可读性,同时允许更轻松地插入逻辑。这并不是一个很大的区别。

即使缩进不正确,if 语句也会执行下一条命令,无论它是否在下一行。不将两个命令放在同一行的唯一原因是调试器支持。

I stand on the ground that braces should match according to indentation.

// This is right.
if (foo) 
{
    // bar
}
else 
{
    // baz
}

while (things) 
{
    // stuff
}

As far as your two examples, I'd consider yours slightly less readable since finding the matching closing parentheses can be hard, but more readable in cases where indentation is incorrect, while allowing logic to be inserted easier. It's not a huge difference.

Even if indentation is incorrect, the if statement will execute the next command, regardless of whether it's on the next line or not. The only reason for not putting both commands on the same line is for debugger support.

九公里浅绿 2024-08-22 06:20:37

我看到的一大优点是,可以更轻松地向带花括号的条件和循环添加更多语句,并且不需要多次额外的击键即可在开始时创建花括号。

The one big advantage I see is that it's easier to add more statements to conditionals and loops that are braced, and it doesn't take many additional keystrokes to create the braces at the start.

何必那么矫情 2024-08-22 06:20:37

我个人的规则是,如果它是一个非常短的“if”,则将其全部放在一行中:

if(!something) doSomethingElse();

通常,我仅在连续出现一堆这样的 if 时才使用它。

if(something == a) doSomething(a);
if(something == b) doSomething(b);
if(something == b) doSomething(c);

不过这种情况并不经常出现,所以除此之外,我总是使用大括号。

My personal rule is if it's a very short 'if', then put it all on one line:

if(!something) doSomethingElse();

Generally I use this only when there are a bunch of ifs like this in succession.

if(something == a) doSomething(a);
if(something == b) doSomething(b);
if(something == b) doSomething(c);

That situation doesn't arise very often though, so otherwise, I always use braces.

§对你不离不弃 2024-08-22 06:20:37

目前,我与一个遵循这一标准的团队一起工作,虽然我对此有抵触情绪,但为了统一起见,我还是遵守了这一标准。

我反对的原因与我反对禁止使用异常、模板或宏的团队的理由相同:如果您选择使用一种语言,请使用整个语言。如果大括号在 C 和 C++ 中是可选的,并且Java 按照惯例强制要求它们,这表明了对该语言本身的一些恐惧。

我理解这里其他答案中描述的危险,并且我理解对统一的渴望,但我不赞成语言子集,除非有一些严格的技术原因,例如仅适用于某些不支持模板的环境的编译器,或与 C 代码的交互,排除了异常的广泛使用。

我每天的大部分时间都在审查初级程序员提交的更改,而出现的常见问题与大括号放置或语句出现在错误的位置无关。危险被夸大了。我宁愿把时间花在更多的实质性问题上,而不是寻找违反编译器乐于接受的内容的行为。

At present, I work with a team that lives by this standard, and, while I'm resistant to it, I comply for uniformity's sake.

I object for the same reason I object to teams that forbid use of exceptions or templates or macros: If you choose to use a language, use the whole language. If the braces are optional in C and C++ and Java, mandating them by convention shows some fear of the language itself.

I understand the hazards described in other answers here, and I understand the yearning for uniformity, but I'm not sympathetic to language subsetting barring some strict technical reason, such as the only compiler for some environment not accommodating templates, or interaction with C code precluding broad use of exceptions.

Much of my day consists of reviewing changes submitted by junior programmers, and the common problems that arise have nothing to do with brace placement or statements winding up in the wrong place. The hazard is overstated. I'd rather spend my time focusing on more material problems than looking for violations of what the compiler would happily accept.

花落人断肠 2024-08-22 06:20:37

一群程序员能够很好地遵循编码标准的唯一方法是将规则的数量保持在最低限度。

平衡收益与成本(每条额外的规则都会让程序员感到困惑,并且在达到一定阈值后,实际上会降低程序员遵循任何规则的机会)

因此,要制定编码标准:

  • 确保您可以证明合理性每条规则都有明确的证据表明它比替代方案更好。

  • 看看该规则的替代方案 - 真的需要吗?如果所有程序员都很好地使用空格(空行和缩进),则 if 语句非常容易阅读,并且即使是新手程序员也不可能将“if”内的语句误认为是独立的语句。如果您遇到许多与 if 作用域相关的错误,根本原因可能是您的空白/缩进样式不佳,这使得代码不必要地难以阅读。

  • 根据规则对代码质量的可衡量影响来确定规则的优先级。通过强制执行规则可以避免多少错误(例如“始终检查 null”、“始终使用断言验证参数”、“始终编写单元测试”与“始终添加一些大括号,即使不需要”) 。以前的规则每年将为您节省数千个错误。大括号规则可能会为你节省一个。也许吧。

  • 保留最有效的规则,舍弃无用的东西。箔条至少是任何比忽略该规则可能出现的 bug 成本更高的规则。但如果您有超过 30 条关键规则,您的程序员可能会忽略其中的许多规则,而您的良好意愿将化为灰尘。

  • 解雇任何在不阅读代码的情况下注释掉随机代码的程序员:-)

PS 我对支撑的立场是:如果“如果” " 语句或者它的内容都是单行,那么你可以省略大括号。这意味着,如果您的 if 包含一行注释和一行代码,则内容将占用两行,因此需要大括号。如果 if 条件跨越两行(即使内容是一行),那么您需要大括号。这意味着您只能在琐碎、简单、易于阅读的情况下省略大括号,而在实践中永远不会犯错误。 (当语句为空时,我不使用大括号,但我总是添加注释清楚地表明它是空的,并且是故意的。但这与另一个主题接壤:在代码中明确,以便读者知道您的意思范围为空而不是电话响了而你忘记完成代码)

The only way coding standards can be followed well by a group of programmers is to keep the number of rules to a minimum.

Balance the benefit against the cost (every extra rule confounds and confuses programmers, and after a certain threshold, actually reduces the chance that programmers will follow any of the rules)

So, to make a coding standard:

  • Make sure you can justify every rule with clear evidence that it is better than the alternatives.

  • Look at alternatives to the rule - is it really needed? If all your programmers use whitespace (blank lines and indentation) well, an if statement is very easy to read, and there is no way that even a novice programmer can mistake a statement inside an "if" for a statement that is standalone. If you are getting lots of bugs relating to if-scoping, the root cause is probably that you have a poor whitepsace/indentation style that makes code unnecessarily difficult to read.

  • Prioritise your rules by their measurable effect on code quality. How many bugs can you avoid by enforcing a rule (e.g. "always check for null", "always validate parameters with an assert", "always write a unit test" versus "always add some braces even if they aren't needed"). The former rules will save you thousands of bugs a year. The brace rule might save you one. Maybe.

  • Keep the most effective rules, and discard the chaff. Chaff is, at a minimum, any rule that will cost you more to implement than any bugs that might occur by ignoring the rule. But probably if you have more than about 30 key rules, your programmers will ignore many of them, and your good intentions will be as dust.

  • Fire any programmer who comments out random bits of code without reading it :-)

P.S. My stance on bracing is: If the "if" statement or the contents of it are both a single line, then you may omit the braces. That means that if you have an if containing a one-line comment and a single line of code, the contents take two lines, and therefore braces are required. If the if condition spans two lines (even if the contents are a single line), then you need braces. This means you only omit braces in trivial, simple, easily read cases where mistakes are never made in practice. (When a statement is empty, I don't use braces, but I always put a comment clearly stating that it is empty, and intentionally so. But that's bordering on a different topic: being explicit in code so that readers know that you meant a scope to be empty rather than the phone rang and you forgot to finish the code)

往昔成烟 2024-08-22 06:20:37

许多语言都有这样的语法(我特别想到perl)来处理这种“丑陋”。所以类似:

if (foo)     
//bar
else     
//baz

可以使用三元运算符写为三元:

foo ? bar : baz

并且

while (something is true)
{
blah 
}

可以写为:

blah while(something is true)

但是在没有这种“糖”的语言中,我肯定会包含大括号。就像你说的那样,它可以防止不必要的错误潜入,并使程序员的意图更加清晰。

Many languanges have a syntax for one liners like this (I'm thinking of perl in particular) to deal with such "ugliness". So something like:

if (foo)     
//bar
else     
//baz

can be written as a ternary using the ternary operator:

foo ? bar : baz

and

while (something is true)
{
blah 
}

can be written as:

blah while(something is true)

However in languages that don't have this "sugar" I would definitely include the braces. Like you said it prevents needless bugs from creeping in and makes the intention of the programmer clearer.

弱骨蛰伏 2024-08-22 06:20:37

我并不是说这是不合理的,但是在 15 年以上使用类似 C 语言的编码中,我没有遇到过省略大括号的问题。注释掉一个分支在理论上听起来像是一个真正的问题——我只是从未在实践中见过它发生。

I am not saying it is unreasonable, but in 15+ years of coding with C-like languages, I have not had a single problem with omitting the braces. Commenting out a branch sounds like a real problem in theory - I've just never seen it happening in practice.

长安忆 2024-08-22 06:20:37

始终使用大括号的另一个优点是它使搜索和替换以及类似的自动化操作变得更容易。

例如:假设我注意到 functionB 通常在 functionA 之后立即调用,具有类似的参数模式,因此我想将重复的代码重构为新的 >组合函数。如果您没有足够强大的重构工具(^\s+functionA.*?;\n\s+functionB.*?;),则正则表达式可以轻松处理此重构,但是没有大括号,一种简单的正则表达式方法可能会失败:

if (x)
  functionA(x);
else
  functionA(y);
functionB();

会变得更

if (x)
  functionA(x);
else
  combined_function(y);

复杂的正则表达式在这种特殊情况下可以工作,但我发现能够使用基于正则表达式的搜索和替换、一次性 Perl 脚本和类似的方法非常方便自动化代码维护,所以我更喜欢不会使代码变得不必要的复杂化的编码风格。

Another advantage of always using braces is that it makes search-and-replace and similar automated operations easier.

For example: Suppose I notice that functionB is usually called immediately after functionA, with a similar pattern of arguments, and so I want to refactor that duplicated code into a new combined_function. A regex could easily handle this refactoring if you don't have a powerful enough refactoring tool (^\s+functionA.*?;\n\s+functionB.*?;) but, without braces, a simple regex approach could fail:

if (x)
  functionA(x);
else
  functionA(y);
functionB();

would become

if (x)
  functionA(x);
else
  combined_function(y);

More complicated regexes would work in this particular case, but I've found it very handy to be able to use regex-based search-and-replace, one-off Perl scripts, and similar automated code maintenance, so I prefer a coding style that doesn't make that needlessly complicated.

表情可笑 2024-08-22 06:20:37

我不同意你的论点。就我个人而言,我不知道有谁“不小心”在 if 下添加了第二行。我会理解说嵌套的 if 语句应该有大括号以避免悬空的 else,但据我所知,您强制执行一种样式是因为担心,IMO,放错地方了。

I don't buy into your argument. Personally, I don't know anyone who's ever "accidentally" added a second line under an if. I would understand saying that nested if statements should have braces to avoid a dangling else, but as I see it you're enforcing a style due to a fear that, IMO, is misplaced.

趁微风不噪 2024-08-22 06:20:37

以下是我遵循的不成文的(我想到目前为止)规则。我相信它在不牺牲正确性的情况下提供了可读性。它基于这样一种信念:在很多情况下,短格式比长格式更具可读性。

  • 如果 if/else if/else 语句的任何块包含多行,请始终使用大括号。注释计数,这意味着条件中任何位置的注释意味着条件的所有部分都得到大括号。
  • 当语句的所有块都是一行时,可以选择使用大括号。
  • 切勿将条件语句与条件放在同一行。 if 语句后面的行始终是有条件执行的。
  • 如果条件语句本身执行必要的操作,则形式将是:

    for (init; term;totalCount++)
    {
        // 故意留空
    }
    

无需以详细的方式对其进行标准化,只需说出以下内容即可:

切勿以牺牲可读性为代价而忽略大括号。如有疑问,请选择使用大括号。

Here are the unwritten (until now I suppose) rules I go by. I believe it provides readability without sacrificing correctness. It's based on a belief that the short form is in quite a few cases more readable than the long form.

  • Always use braces if any block of the if/else if/else statement has more than one line. Comments count, which means a comment anywhere in the conditional means all sections of the conditional get braces.
  • Optionally use braces when all blocks of the statement are exactly one line.
  • Never place the conditional statement on the same line as the condition. The line after the if statement is always conditionally executed.
  • If the conditional statement itself performs the necessary action, the form will be:

    for (init; term; totalCount++)
    {
        // Intentionally left blank
    }
    

No need to standardize this in a verbose manner, when you can just say the following:

Never leave braces out at the expense of readability. When in doubt, choose to use braces.

成熟稳重的好男人 2024-08-22 06:20:37

我认为大括号的重要之处在于它们非常明确地表达了程序员的意图。您不必从缩进推断意图。

也就是说,我喜欢格斯建议的单行返回和继续。意图很明显,而且更清晰、更容易阅读。

I think the important thing about braces is that they very definitely express the intent of the programmer. You should not have to infer intent from indentation.

That said, I like the single-line returns and continues suggested by Gus. The intent is obvious, and it is cleaner and easier to read.

戏剧牡丹亭 2024-08-22 06:20:37

如果您有时间阅读所有这些内容,那么您就有时间添加额外的大括号。

If you have the time to read through all of this, then you have the time to add extra braces.

残花月 2024-08-22 06:20:37

为了可维护性,我更喜欢在单行条件语句中添加大括号,但我可以看到不使用大括号如何看起来更干净。这并不困扰我,但有些人可能会因为额外的视觉噪音而失去兴趣。

我也无法提供更好的反驳。对不起! ;)

I prefer adding braces to single-line conditionals for maintainability, but I can see how doing it without braces looks cleaner. It doesn't bother me, but some people could be turned off by the extra visual noise.

I can't offer a better counterargument either. Sorry! ;)

蹲墙角沉默 2024-08-22 06:20:37

对于这样的事情,我建议只为 IDE 的自动格式化程序提供一个配置模板。然后,每当您的用户按下 alt-shift-F(或您选择的 IDE 中的任何击键)时,都会自动添加大括号。然后对每个人说:“继续更改字体颜色、PMD 设置或其他任何内容。不过,请不要更改缩进或自动大括号规则。”

这利用了我们可用的工具来避免争论那些确实不值得通常花费氧气的事情。

For things like this, I would recommend just coming up with a configuration template for your IDE's autoformatter. Then, whenever your users hit alt-shift-F (or whatever the keystroke is in your IDE of choice), the braces will be automatically added. Then just say to everyone: "go ahead and change your font coloring, PMD settings or whatever. Please don't change the indenting or auto-brace rules, though."

This takes advantage of the tools available to us to avoid arguing about something that really isn't worth the oxygen that's normally spent on it.

じее 2024-08-22 06:20:37

根据语言的不同,单行条件语句或循环语句不必使用大括号。事实上,我会删除它们以减少代码行数。

C++:

版本 1:

class InvalidOperation{};

//...
Divide(10, 0);
//...
Divide(int a, in b)
{
   if(b == 0 ) throw InvalidOperation();
   return a/b;
}

版本 2:

class InvalidOperation{};

//...
Divide(10, 0);
//...
Divide(int a, in b)
{
   if(b == 0 )
   { 
      throw InvalidOperation();
   }
   return a/b;
}

C#:

版本 1:

foreach(string s in myList)
   Console.WriteLine(s);

版本 2:

foreach(string s in myList)
{
   Console.WriteLine(s);
}

根据您的观点,版本 1 或版本 2 会更具可读性。答案相当主观

Depending on the language, having braces for a single lined conditional statement or loop statement is not mandatory. In fact, I would remove them to have fewer lines of code.

C++:

Version 1:

class InvalidOperation{};

//...
Divide(10, 0);
//...
Divide(int a, in b)
{
   if(b == 0 ) throw InvalidOperation();
   return a/b;
}

Version 2:

class InvalidOperation{};

//...
Divide(10, 0);
//...
Divide(int a, in b)
{
   if(b == 0 )
   { 
      throw InvalidOperation();
   }
   return a/b;
}

C#:

Version 1:

foreach(string s in myList)
   Console.WriteLine(s);

Version2:

foreach(string s in myList)
{
   Console.WriteLine(s);
}

Depending on your perspective, version 1 or version 2 will be more readable. The answer is rather subjective.

怪我鬧 2024-08-22 06:20:37

哇。 没有人知道悬空else问题?这本质上就是始终使用大括号的原因。

简而言之,else 语句可能会产生令人讨厌的模糊逻辑,尤其是当它们嵌套时。不同的编译器以自己的方式解决歧义。如果您不知道自己在做什么,那么放弃牙套可能会是一个大问题。

美观和可读性无关。

Wow. NO ONE is aware of the dangling else problem? This is essentially THE reason for always using braces.

In a nutshell, you can have nasty ambiguous logic with else statements, especially when they're nested. Different compilers resolve the ambiguity in their own ways. It can be a huge problem to leave off braces if you don't know what you're doing.

Aesthetics and readability has nothing to do it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文