如果你打破长代码行,你如何缩进下一行的东西? [英] If you break long code lines, how do you indent the stuff on the next line?

查看:170
本文介绍了如果你打破长代码行,你如何缩进下一行的东西?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有时你必须在你的源代码中写长行,这样更好的打破。



您可以缩进一样:

 很长
语句;
其他语句;

这使得更难区别于下面的代码,如示例所示。另一方面,你可以缩进一级:

 很长
语句;
其他语句;

这使得更容易,但可能发生,长行是嵌套块的开始,您想缩进,像这样:

  if((long test 1)&& 
长测试2)&&
(长测试3)){
如果为真,则执行代码;
}

在这种情况下,它很难阅读。我可以想到的第三种可能性是,不要打破长线,现代编辑可以处理它,并创建软线破裂。但是使用另一个编辑器,你必须横向滚动,不能影响位置,编辑器打破了你的长线。



你更喜欢什么可能性?你有其他想法来解决这个问题吗?

解决方案

我喜欢大括号在自己的行上,因为我很容易看到条件和内部块都作为一个项目(如果你知道我的意思):

  if((long test 1)
$ b {
如果为true,则执行代码;


&
}

我喜欢用条件开始附加条件行,因为我发现加入条件是非常重要的,它往往在上一行的末尾被忽略。



我也尝试和缩进,使括号的效果是明显的(虽然试图避免长条件语句通常是一件好事)。



我尝试和结构化的东西,以便我可以轻松地扫描东西 p>

Sometimes you have to write in your source long lines, that are better to break. How do you indent the stuff ceated by this.

You can indent it the same:

very long
statement;
other statement;

That makes it harder to differentiate from the following code, as shown in the example. On the other hand you could indent it one level:

very long
   statement;
other statement;

That makes it easier, but it can happen, that the long line is the start of a nested block, that you want to indent, like this:

if ((long test 1) &&
   (long test 2) &&
   (long test 3)) {
   code executed if true;
}

In this case again it's hard to read. The third possibility I can think of, is to not break long lines at all, modern editors can handle it and create soft linebreaks. But with another editor you have to scroll sideways and you cannot influence the position, the editor breaks your long line.

What possibility do you prefer? Do you have other ideas to solve this? Can you support your preference with a good justification?

解决方案

I like braces on their own line because I fine it easier to see the condition and inner block all as one item (if you know what I mean):

if ((long test 1)
    && (long test 2)
    && (long test 3)) 
{
    code executed if true;
}

and I like starting additional conditional lines with what the condition is because I find that the "joining" condition is very important and it tends to get overlooked at the end of the previous line.

I also try and indent such that the effect of parenthesis are obvious (though trying to avoid long conditionals is generally a good thing).

I try and structure stuff so that I can easily "scan" for "stuff" :)

这篇关于如果你打破长代码行,你如何缩进下一行的东西?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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