临时局部变量的命名规则 [英] naming convention of temp local variables

查看:219
本文介绍了临时局部变量的命名规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是命名的本地功能的临时变量的标准方法是什么?让我给你的,我做的事情的说明。我得到一个指向结构的指针,所以我想存储其成员之一在本地,以避免解除引用,然后再进行任何修改分配回指针。

What is the standard way to name a temp variable in the local function? let me give you an illustration of what I am doing. I get a pointer to a structure, so I want store one of its members locally to avoid a de-referenced, and then any modification assign back to the pointer.

要更具体:

struct  Foo
{
  double m_d;

};


void function (Foo* f)
{
   double tmp=f->m_d;

       /***Other stuff***/

     f->m_d=tmp;
}

我不喜欢 TMP 。如果我有很多人在一个​​函数,他们只添加混乱。

I don't like tmp. If I have many of them in a function, they only add a confusion.

感谢

推荐答案

Linus Torvalds公司 - Linux内核编码风格从Linus Torvalds公司

Linus Torvalds - Linux Kernel coding style from Linus Torvalds :

本地变量名应该简短,并以点。如果你有
  一些随机整数循环计数器,它或许应该被称为I。
  称之为loop_counter是非生产性,如果没有它的机会
  是错误的理解。同样,tmp可以作为几乎任何类型的
  变量用于保持临时值。

LOCAL variable names should be short, and to the point. If you have some random integer loop counter, it should probably be called "i". Calling it "loop_counter" is non-productive, if there is no chance of it being mis-understood. Similarly, "tmp" can be just about any type of variable that is used to hold a temporary value.

如果你怕混淆了你的本地变量名,你有另一个
  的问题,这就是所谓的函数增长激素失调综合征。

If you are afraid to mix up your local variable names, you have another problem, which is called the function-growth-hormone-imbalance syndrome.

这篇关于临时局部变量的命名规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆