2

I would like to follow conventions including that not exceed 80 characters per line.

I downloaded the PDF explaining the naming class, variables, and speaking a bit of wrapping but it's still light.

It is stated: - break after a comma - break before an operator - prefer high level breaks to lower

But how to manage a simple case as this one :

File logDir = new File(PropertiesLoader.getProperty(SpecificConstant.AdminStorageProperty.LOG_FOLDER.getValue()));

I am tempted to wrap after the parenthesis of getProperty.

If we cut before an operator, must we do that for all the following operators? I often see this code:

String value = SpecificConstant
    .AdminStorageProperty
    .LOG_FOLDER
    .getValue();

What is the better way to wrap lines ?

Thank you.

4

3 回答 3

6

我使用 IDE 的默认设置,因此它会在我签入或要求时自动格式化我的代码。我很少手动格式化代码。

我会写

 File logDir = new File(PropertiesLoader.getProperty(SpecificConstant.AdminStorageProperty.LOG_FOLDER.getValue()));

as(在我的 IDE 中使用引入变量重构)

 String logProp = SpecificConstant.AdminStorageProperty.LOG_FOLDER.getValue();
 File logDir = new File(PropertiesLoader.getProperty(logProp));

我在我的 IDE 中使用了比例字体,使 80 个字符的限制变得不那么有意义;)对我来说,它通常更像是 200 个字符的限制。

于 2013-01-21T10:28:52.253 回答
0

恕我直言,80 宽度有点过时了,因为当时分辨率低,屏幕最好用 80 读取。

我在 IDE 中使用 120 作为默认宽度,并将其格式化为完全可读的代码。

File logDir = new File(PropertiesLoader.getProperty(SpecificConstant.AdminStorageProperty.LOG_FOLDER.getValue()));
于 2013-01-21T11:17:58.450 回答
0

请参阅Oracle的 Java 代码约定

于 2013-01-21T11:23:55.450 回答