我有以下的.cpp文件:
////////////////////////////////////////////////////////////////////////////////
void call_long_function_name(bool) {}
void sf(bool) {}
int main() {
bool test = true;
if (test) { call_function_name(test); }
if (test) { sf(test); }
return 0;
}
(斜杠分隔80个字符)。使用以下配置文件,clang-format建议:
////////////////////////////////////////////////////////////////////////////////
void call_long_function_name(bool) {}
void sf(bool) {}
int main() {
bool test = true;
if (test) {
call_function_name(test);
}
if (test) {
sf(test);
}
return 0;
}
尽管在文件中我允许短的if语句放在一行内,但是您觉得我设置了错误的选项吗?
哪些选项可以用来最小化浪费的垂直空间?
Clang-format的.clang-format文件
BasedOnStyle: Google
AccessModifierOffset: -1
AlignEscapedNewlinesLeft: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortFunctionsOnASingleLine: true
AllowShortIfStatementsOnASingleLine: true
AllowShortLoopsOnASingleLine: true
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: false
BinPackParameters: true
BreakBeforeBinaryOperators: true
BreakBeforeBraces: Attach
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: true
ColumnLimit: 80
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 2
ContinuationIndentWidth: 0
Cpp11BracedListStyle: true
DerivePointerBinding: true
IndentCaseLabels: true
IndentFunctionDeclarationAfterType: true
IndentWidth: 2
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
PointerBindsToType: true
SpaceAfterControlStatementKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 2
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInAngles: false
Standard: Cpp11
TabWidth: 2
UseTab: Never
if (test) call_function_name(test);
然而,请问您认为垂直空间是浪费的吗?难道它不是一种珍贵的资源需要节约吗?并非如此。顺便说一下,如果call_function_name(test)
与if
在同一行上,则很难在调试器中在该语句处设置断点。 - David Hammen