前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >C++核心准则ES.21: 不要在不需要时引入变量(或常量)

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

作者头像
面向对象思考
发布2020-04-26 12:09:25
2250
发布2020-04-26 12:09:25
举报

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(示例)

代码语言:javascript
复制
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

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2020-04-24,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 面向对象思考 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • ES.21: Don't introduce a variable (or constant) before you need to use it
  • Reason(原因)
    • Enforcement(实施建议)
    领券
    问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档