ES.21: Don't introduce a variable (or constant) before you need to use it
ES.21: 不要在不需要時引入變量(或常量)
Reason(原因)
Readability. To limit the scope in which the variable can be used.
可讀性。爲了限定變量可用的作用域。
Example(示例)
int x = 7;
// ... no use of x here ...
++x;
Enforcement(實施建議)
Flag declarations that are distant from their first use.
標記遠離首次使用代碼的變量定義。
原文鏈接
https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#es21-dont-introduce-a-variable-or-constant-before-you-need-to-use-it
覺得本文有幫助?歡迎點贊並分享給更多的人。
閱讀更多更新文章,請關注微信公衆號【面向對象思考】