Vertical Whitespace
c++规范,github:https://google.github.io/styleguide/cppguide.html#Vertical_Whitespace
This is more a principle than a rule: don't use blank lines when you don't have to. In particular, don't put more than one or two blank lines between functions, resist starting functions with a blank line, don't end functions with a blank line, and be sparing with your use of blank lines. A blank line within a block of code serves like a paragraph break in prose: visually separating two thoughts.
这与其说是规则,不如说是一个原则:如果不需要,就不要使用空行 。特别是,函数之间不要放置超过一两个空行,避免以空行开始函数,不要以空行结束函数,并且要谨慎使用空行。代码块中的空行就像散文中的段落分隔符:在视觉上将两个思想分开。
基本原则是:屏幕上显示的代码越多,就越容易理解程序的控制流程。有目的地使用空白来提供流程中的分隔。
一些有助于确定何时可能需要空行的经验法则:
- 函数开头或结尾的空行无助于提高可读性。
- if-else 块中的空行可能会提高可读性。
- 在注释行前留空行通常有助于 提高可读性------新注释的引入暗示着新思想的开始,而空行则清楚地表明 该注释与后面的内容相关,而不是前面的内容。
最佳实践
在逻辑上相关的代码块之间保持适度的空白
不要过度使用,避免代码过于稀疏
保持一致的空白风格