变量和typename命名 [英] Variable and typename naming

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

问题描述

在C中,如果我想要类型名称和变量的类似名称,

有什么好的方法可以推荐我这样做吗?


For例如,我有一个包含一个区域的结构,

我已经命名了它,相应地,结构区域,现在当我用
声明变量时,我想拥有相同的,或者一个非常类似的名字,因为我不能提出另一个好名字。


现在,因为不同的命名空间,我可以声明它

结构区域。

但是这可能是模糊不清的编码习惯吗?

或者也许在类型名称中加上一个大写字母,比如

struct Region区域,甚至是一个

typedef struct region {...} Region。我不知道,

所以我很感激答案。


谢谢!

In C, if I want similar names for typename and variable,
is there any good way you can recommend me to do that?

For example, I have a struct containing a region, which
I have named it, appropriately, struct region, now when I
declare variables, I want to have the same, or a very
similar name, since I can''t come up with another good name.

Now, because the different namespaces, I could declare it
struct region region.
But maybe that is obscure and bad coding practice?
Or maybe put a captial letter in the typename, like
struct Region region, or even a
typedef struct region { ... } Region. I don''t know,
so I''m grateful for answers.

Thanks!

推荐答案

在文章< ob ******************* @ newsb.telia.net> ;,

Edward Gregor< ed **** @ hotmail.com>写道:
In article <ob*******************@newsb.telia.net>,
Edward Gregor <ed****@hotmail.com> wrote:
在C中,如果我想要类型名称和变量的相似名称,
有什么好的方法可以推荐我这样做吗?
例如,我有一个包含一个区域的结构,我已经命名了它,相应地,结构区域,现在当我声明变量时,我想拥有相同的,或者非常的
名字相似,因为我不能提出另一个好名字。
现在,因为不同的名称空间,我可以声明它结构区域区域。
但也许这是不明确和糟糕的编码实践?


是的。

或者在类型名称中加上一个大写字母,比如
struct Region区域,甚至是
typedef结构region {...} Region。我不知道,
所以我很感激答案。
In C, if I want similar names for typename and variable,
is there any good way you can recommend me to do that? For example, I have a struct containing a region, which
I have named it, appropriately, struct region, now when I
declare variables, I want to have the same, or a very
similar name, since I can''t come up with another good name. Now, because the different namespaces, I could declare it
struct region region.
But maybe that is obscure and bad coding practice?
Yeah.
Or maybe put a captial letter in the typename, like
struct Region region, or even a
typedef struct region { ... } Region. I don''t know,
so I''m grateful for answers.




使用略有不同的表格来表示不同的颜色并不少见br />
逻辑层。例如,有些人可能会使用


struct region_s {...};

typedef struct region_s region_t;

region_t region ;


有不同的命名系统正在使用中,特别是当它来到程序时。例如,有些人

runthenamestogether,有些人用CapitalizeEachWord,

有些人用use_underscores_between_words,有些名字

程序带有后缀组合,表示类型

它运作;并且有些人强制要求

a程序名必须是动词(例如,die())否则

必须是表示动词和a的子句(可能合格的)名词

(例如,TotalSalaries,print_small_cheques)。 [这样做的人

通常也对对象标识符有特定的格式要求。]


-

"它是重要的是要记住,当涉及到法律时,电脑

永远不会复制,只有人类才能复制。计算机给出了

命令,而非许可。只有人才能获得许可。

- Brad Templeton



It isn''t uncommon to use slightly different forms for different
logical layers. For example, some people might use

struct region_s { ... };
typedef struct region_s region_t;
region_t region;

There are different naming systems in use, especially when
it comes to procedures. For example, some people
runthenamestogether, some people CapitalizeEachWord,
some people use_underscores_between_words, some name
procedures with a suffix combination that indicates the types
it operates on; and some people impose the requirement that
a procedure name must either be a verb (e.g., die()) or else
must be a clause indicating a verb and a (possibly qualified) noun
(e.g., TotalSalaries, print_small_cheques). [People who do that
often also have particular format requirements for object identifiers.]

--
"It is important to remember that when it comes to law, computers
never make copies, only human beings make copies. Computers are given
commands, not permission. Only people can be given permission."
-- Brad Templeton


Walter Roberson写道:
Walter Roberson wrote:
struct region_s {...};
typedef struct region_s region_t;
region_t region;
struct region_s { ... };
typedef struct region_s region_t;
region_t region;




在这个例子中_s和_t足以代表什么?


感谢您的帮助!



What would the _s and _t suffices stand for in this example?

Thanks for the help!


Edward Gregor< ed **** @ hotmail.com>写道:
Edward Gregor <ed****@hotmail.com> writes:
Walter Roberson写道:
Walter Roberson wrote:
struct region_s {...};
typedef struct region_s region_t;
region_t region;
struct region_s { ... };
typedef struct region_s region_t;
region_t region;



在这个例子中_s和_t足以代表什么?



What would the _s and _t suffices stand for in this example?




struct和type或typedef分别。


(就我个人而言,我不打算使用typedef。struct region是一个非常好的名字;这个名字没什么好处发明另一个名字。$

-

基思汤普森(The_Other_Keith) ks *** @ mib.org < http://www.ghoti.net/~kst>

圣地亚哥超级计算机中心< * > < http://users.sdsc.edu/~kst>

我们必须做点什么。这是事情。因此,我们必须这样做。



struct and type or typedef, respectively.

(Personally, I wouldn''t bother with the typedef. "struct region" is a
perfectly good name for the type; there''s little advantage in
inventing another name for it.)

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.


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

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