<分区>
我想遵循每行不超过 80 个字符的约定。
我下载了解释命名类、变量和一些换行的 PDF,但它仍然很简单。
据说:
- 在逗号后中断
- 在运算符(operator)之前中断
- 更喜欢高位突破而不是低位
但是如何管理像这样的简单案例:
File logDir = new File(PropertiesLoader.getProperty(SpecificConstant.AdminStorageProperty.LOG_FOLDER.getValue()));
我很想在 getProperty 的括号后换行。
如果我们在一个运算符之前剪切,我们是否必须对后面的所有运算符都这样做?
我经常看到这段代码:
String value = SpecificConstant
.AdminStorageProperty
.LOG_FOLDER
.getValue();
换行的更好方法是什么?
谢谢。
我使用我的 IDE 的默认设置,因此它会在我 checkin 代码时或在我要求时自动格式化我的代码。我很少手动格式化代码。
我会写
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 个字符的限制。