代码行包装 - 如何处理长行 [英] Code line wrapping - how to handle long lines

查看:141
本文介绍了代码行包装 - 如何处理长行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我面对的是一个长度为153个字符的特定行。现在,我倾向于打破120个字符后的东西(当然,这在很大程度上取决于我在哪里和当地的惯例。)但是说实话,无处不在我打破线只是使它看起来不好。所以我正在寻找一些关于我应该做什么的想法。

I'm facing a particular line that is 153 characters long. Now, I tend to break things after 120 characters (of course, this is heavily dependent on where I am and the local conventions.) But to be honest, everywhere I break the line just makes it look bad. So I'm looking for some ideas on what I should do for it.

这是这行:

private static final Map<Class<? extends Persistent>, PersistentHelper> class2helper = new HashMap<Class<? extends Persistent>, PersistentHelper>();

我对两个想法都很开放,以及缩短线本身的方法。

I'm open to both ideas about how/where to break the line (and why), as well as ways to shorten the line itself.

我们不是一个Java商店,并没有这种事情的本地约定,或者显然我会简单地跟随他们。

We're not a Java shop, and there aren't local conventions for this sort of thing, or obviously I would simply follow them.

谢谢!

推荐答案

之前的 运算符,并缩进后面的行:

In general, I break lines before operators, and indent the subsequent lines:

Map<long parameterization>
    = new HashMap<ditto>();

String longString = "some long text"
                  + " some more long text";

对我来说,领先的运营商清楚地表达这条线从别的东西继续,独立自主。其他人当然有不同的偏好。

To me, the leading operator clearly conveys that "this line was continued from something else, it doesn't stand on its own." Other people, of course, have different preferences.

这篇关于代码行包装 - 如何处理长行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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