命名对话 [英] naming convetions

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

问题描述



我有问题给我的结构好名字,我通常在它们之后命名

(当然)所以如果我有,比如说,< br $>
窗口结构,我把它命名为struct window,我通常都不会打扰它/ b $ b键入它们。但是现在我不能把这个窗口用作变量名

(是的,我知道我*可以*,但我不会,我不想被混淆

通过对结构和变量使用相同的名称。)

我可以在窗口上执行

操作的函数中使用名称w作为变量,这是有效的,但如果我添加一个结构

小部件,我不希望它在功能上也有名称w。

我想要保持一致我在函数

参数中的变量命名,对于两个窗口使用w将会很困惑

和小部件。当然我可以使用wt或任何东西作为

变量名,但我想也许我应该更改结构的

名称,以便我可以自由选择名称

变量。

也许在前缀或后缀结构名称,我已经看到

名称以_t结尾的类型,但是这违反了标准,

对吗?也许_s是一个不错的选择?


所以我要求的是你对我应该如何命名的意见

。我知道有很多不同的风格和这个,但我必须选择自己,但我会很高兴地接受你的任何意见。我想知道是否有任何常见的或pouplar方式来命名。

。谢谢!na

Hi
I have problems giving my structs good names, I usually name
them after what they are (of course) so if I have, say, a
window struct, I name it struct window, I usually don''t bother
typedefing them. But now I can''t use the window as variable name
(yes, I know I *can*, but I won''t, I don''t want to be confused
by using the same name for both struct and variable).
I can use the name w for the variable in functions that do
operations on the window, that works, but if I add a struct
widget, I don''t want that to also have the name w in function.
I want to be consistent in my variable naming in the function
arguments, and it would be confusing to use w for both windows
and widgets. Of course I can just use wt or anything as a
variable name, but I thought maybe I should change the
name of the struct so that I can freely choose the names of
the variables.
Maybe prefixing or postfixing the structname, I''ve seen
names ending with _t for type, but that violates the standard,
right? Maybe _s is a good choice?

So what I''m asking for is your opinions on how I should name
things. I understand that there are many different styles and
tastes of this, and that I have to choose myself, but I''ll
gladly take any opinions from you. I want to know if there is
any common or pouplar way to name things. Thank you!na

推荐答案

Jyrgen说:
Jyrgen said:



我有问题给我的结构好名字,我通常在它们之后命名

(当然)所以如果我有一个

窗口结构,我把它命名为struct window,我通常不打扰

键入它们。但是现在我不能把这个窗口用作变量名

(是的,我知道我*可以*,但我不会,我不想被混淆

通过对结构和变量使用相同的名称)。
Hi
I have problems giving my structs good names, I usually name
them after what they are (of course) so if I have, say, a
window struct, I name it struct window, I usually don''t bother
typedefing them. But now I can''t use the window as variable name
(yes, I know I *can*, but I won''t, I don''t want to be confused
by using the same name for both struct and variable).



考虑使用C区分大小写的事实。或者,考虑

将对象的目的作为其名称的一部分添加。例如:


struct window main_window;

struct window edit_window;

struct window logging_window;





-

Richard Heathfield

Usenet是一个奇怪的地方 - dmr 29/7/1999
http://www.cpax.org.uk

电子邮件:rjh在上面的域名(但显然放弃了www)

Consider using the fact that C is case sensitive. Alternatively, consider
adding in the purpose of the object as part of its name. For example:

struct window main_window;
struct window edit_window;
struct window logging_window;

etc.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)


Jyrgen写道:
Jyrgen wrote:

我有问题给我的结构好名字,我通常将它们命名为

它们是什么(当然)所以如果我有,比如说,

窗口结构,我将其命名为struct window,我通常不会打扰

键入它们。
I have problems giving my structs good names, I usually name
them after what they are (of course) so if I have, say, a
window struct, I name it struct window, I usually don''t bother
typedefing them.



另一方面,像`window * w'这样的声明比`struct window更短(并且比b
更可读) * w''。

On the other hand, a declaration like `Window *w'' is shorter (and imho
more readable) than `struct window *w''.


但现在我不能将窗口用作变量名

(是的,我知道我*可以*,但我不会,我不想因为结构和变量使用相同的名称而混淆

)。
But now I can''t use the window as variable name
(yes, I know I *can*, but I won''t, I don''t want to be confused
by using the same name for both struct and variable).



至少我发现`Window * window''比'struct

window * window''更令人困惑。

At least I find `Window *window'' to be less confusing than `struct
window *window''.


我可以在窗口上执行

操作的函数中使用名称w作为变量,有效,
I can use the name w for the variable in functions that do
operations on the window, that works,



对我来说听起来很明智。唯一的例外是单字母名称,如l,

我,o和O。

Sounds sensible to me. The only exception is one-letter names like `l'',
`I'', `o'' and `O''.


但是如果我添加一个struct

小部件,我不希望它在函数中也有名称w。
but if I add a struct
widget, I don''t want that to also have the name w in function.



在这种情况下,我会拼出名字:


void foo(Window * window,Widget * widget);


或者可以使用


void foo(Window * win,Widget * wid);

In this case I would spell out the names:

void foo(Window* window, Widget *widget);

or maybe use

void foo(Window* win, Widget *wid);


我希望在函数中的变量命名中保持一致

参数,
I want to be consistent in my variable naming in the function
arguments,



绝对一致性不一定是好的事情。请注意,您为导出功能选择的
名称更为重要,因为客户将使用这些名称

Absolute consistency is not necessarily a good thing. Note that the
names you choose for exported features are more important, since these
names will be used by clients.


和两个窗口使用w会很混乱

和小部件。
and it would be confusing to use w for both windows
and widgets.



如果他们没有出现在同一个函数中,我认为没问题。

If they don''t occur in the same function I see no problem.


也许前缀或后缀结构名称,我已经看到

名称以_t结尾的类型,但这违反了标准,

对吗?也许_s是个不错的选择?
Maybe prefixing or postfixing the structname, I''ve seen
names ending with _t for type, but that violates the standard,
right? Maybe _s is a good choice?



就个人而言,我不喜欢匈牙利表示法。

八月

Personally, I don''t like Hungarian notation.
August


On Sun,2006年8月6日11:38:52 UTC,Jyrgen< jy **** @ has.no.mailwrote:
On Sun, 6 Aug 2006 11:38:52 UTC, Jyrgen <jy****@has.no.mailwrote:

Hi

我有问题给我的结构好名字,我通常将它们命名为

它们是什么(当然)所以如果我有一个

窗口结构,我把它命名为struct window,我通常不会打扰它们给它们打字。但是现在我不能把这个窗口用作变量名

(是的,我知道我*可以*,但我不会,我不想被混淆

通过对结构和变量使用相同的名称)。
Hi
I have problems giving my structs good names, I usually name
them after what they are (of course) so if I have, say, a
window struct, I name it struct window, I usually don''t bother
typedefing them. But now I can''t use the window as variable name
(yes, I know I *can*, but I won''t, I don''t want to be confused
by using the same name for both struct and variable).



定义结构时,您正在定义一种模板。当你定义一个变量来定义一个特定的对象。


struct car是一种规范的汽车,struct house是一个规范的房子。
< br $>
struct car ford是一个特定的汽车,结构房子my_home是一个特定的

房子。


所以找到一个通用名称结构和

对象的更具体的名称。


对于typedef,我使用全部大写来表明它是一种类型。无论如何我

不要使用匈牙利符号一致但首字母P(类型)或p

(对象)标记指针以区分它们与同类型的类型/变量< br $>
名称。


所以我有


ADDRESS地址;

PADDRESS paddress;


CUSTOMER客户;

PCUSTOMER pcustomer;


pCustomer createCustomer(PCUSTOMER pcustomer,/ *客户列表* /

PADDRESS paddress,/ * NULL或已知

地址* /

PPHONE pphone,/ * NULL或客户

手机* /

.....);

-

Tschau / Bye

Herbert


访问 http://www.ecomstation.de 德国eComStation的主页

eComStation 1.2 Deutsch ist da!

When you defines a struct you are defining a kind of template. When
you defines a variable you defines a specific object.

struct car is a normative car, struct house is a normative house.

struct car ford is a specific car, struct house my_home is a specific
house.

So find a generic name for the struct and a more specific name for the
objects.

For typedef I use all uppercase to show up that it is a type. Anyway I
don''t use hungarian notation consistent but first letter P (type) or p
(object) flags pointers to distinguish them from type/variable of same
name.

So I have

ADDRESS address;
PADDRESS paddress;

CUSTOMER customer;
PCUSTOMER pcustomer;

pCustomer createCustomer(PCUSTOMER pcustomer, /* list of customers */
PADDRESS paddress, /* NULL or known
address */
PPHONE pphone, /* NULL or customers
phone */
.....);
--
Tschau/Bye
Herbert

Visit http://www.ecomstation.de the home of german eComStation
eComStation 1.2 Deutsch ist da!


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

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