C++核心准则ES.21: 不要在不需要时引入变量(或常量)

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

 


 

觉得本文有帮助?欢迎点赞并分享给更多的人。

阅读更多更新文章,请关注微信公众号【面向对象思考】

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章