相关疑难解决方法(0)

为什么省略花括号被认为是一种不好的做法?

为什么每个人都告诉我编写这样的代码是一种不好的做法?

if (foo)
    Bar();

//or

for(int i = 0 i < count; i++)
    Bar(i);
Run Code Online (Sandbox Code Playgroud)

省略花括号的最大理由是它有时可以是它们的两倍.例如,下面是一些为C#中的标签绘制发光效果的代码.

using (Brush br = new SolidBrush(Color.FromArgb(15, GlowColor)))
{
    for (int x = 0; x <= GlowAmount; x++)
    {
        for (int y = 0; y <= GlowAmount; y++)
        {
            g.DrawString(Text, this.Font, br, new Point(IconOffset + x, y));
        }
     }
 }
 //versus
using (Brush br = new SolidBrush(Color.FromArgb(15, GlowColor)))
    for (int x = 0; x <= GlowAmount; x++)
        for (int y = 0; y <= GlowAmount; y++) …
Run Code Online (Sandbox Code Playgroud)

c c# c++ java coding-style

177
推荐指数
29
解决办法
5万
查看次数

标签 统计

c ×1

c# ×1

c++ ×1

coding-style ×1

java ×1