私有函数的命名 [英] Naming of private functions

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

问题描述

我工作的公司使用的命名惯例是我之前从未使用过的
。他们使用混合大小写字母用于公共

成员函数,但小写字母用下划线表示

休息,如下所示:


class Foo

{

public:

void somePublicMemberFunction();

protected:

void hello_i_am_protected();

private:

void this_one_is_private();

};


其他开发者发誓这个约定使代码更容易理解,但是没有一个可以给我一个具体的

理由。


顺便说一下,在我之前的工作中,我总是非常愉快地对所有成员函数使用相同的

约定,但在使用这个新成员后几个月使用
我仍然不相信

它增加了价值。


我明白私人*数据*成员值得追尾

下划线或m_前缀,以区别于本地

变量或函数参数,但是nee对于这个

的约定我根本不清楚。


任何人都能看到这些好处吗?

解决方案

如果先前保护/私有方法被''提升''

公开,会议的惯例是什么?搜索和替换名称更改?


Derek写道:


我工作的公司使用我拥有的命名约定从未使用过。他们使用混合大小写的字母作为公共
成员函数,但小写字母带有下划线用于
休息,如下:

class Foo
{
public:
void somePublicMemberFunction();
protected:
void hello_i_am_protected();
private:
void this_one_is_private();
};

其他开发人员发誓这个约定使代码更容易理解,但是没有一个可以给我一个具体的理由。

顺便说一句,在我的以前的工作我总是非常愉快地对所有会员功能使用相同的
约定,但在使用这个新的几个月之后,我仍然不相信它会增加价值。

我知道private * data *成员应该使用尾随的下划线或m_前缀来区分它们与本地变量或函数参数,但是这个
约定的需要不是对我来说很清楚。

任何人都能看到好处吗?


-

Bret Pehrson

mailto:br ** @ infowest.com

NOSPAM - 在所有电子邮件通信中包含此密钥<< 38952rglkwdsl>>


" Derek" < me@nowhere.special.com>写了...

我工作的公司使用了我之前从未使用的命名约定。他们使用混合大小写的字母作为公共
成员函数,但小写字母带有下划线用于
休息,如下:

class Foo
{
public:
void somePublicMemberFunction();
protected:
void hello_i_am_protected();
private:
void this_one_is_private();
};

其他开发人员发誓这个约定使代码更容易理解,但是没有一个可以给我一个具体的理由。


命名约定旨在为读者提供一种方式来快速了解符号的某些内容,在您的情况下它是

可能的事实是该功能是(a)成员和(b)

a公共或私人/受保护的。如果在你的项目中

对符号的访问权限产生了不同,那么

证明对函数有不同的命名约定,

那些差异只有那些参与项目的人才知道......

顺便说一下,在我之前的工作中,我总是使用相同的
约定。所有成员的职能都非常愉快,但在使用这个新成员几个月后,我仍然不相信它会增加价值。


然后你必须与那些建立这样命名的人讨论

惯例。除非你的一位同事也读到这个NG

,否则最好离线。如果没有看到更多代码或者甚至工作一段时间,我们怎么可能成功地猜出作者的意图
$ b $约定的b?

我理解私有*数据*成员应该有一个尾随的下划线或m_前缀来区分它们与本地变量或函数参数,但是需要这个
约定对我来说根本不清楚。

任何人都能看到这些好处?




我不能说我已经_used_这样的约定,但是那里有一些可能的东西,否则为什么人们会使用它来保持

?但是,唉,我不能说我看到了。 :-)


V


Bret Pehrson写道:

什么是如果先前受保护/私人的方法被提升为公众,那么约定?搜索和替换名称
更改?




是的。优雅,不是吗? :)


The company where I work uses a naming convention that I have
never used before. They use mixed-case letters for public
member functions, but lower-case with underscores for the
rest, like this:

class Foo
{
public:
void somePublicMemberFunction();
protected:
void hello_i_am_protected();
private:
void this_one_is_private();
};

The other developers swear that this convention makes code
easier to understand, but not one of can give me a concrete
justification.

Incidentally, in my previous jobs I always used the same
convention for all member functions quite happily, but after
several months of using this new one I''m still not convinced
it adds value.

I understand that private *data* members deserve a trailing
underscore or m_ prefix to differentiate them from local
variables or function arguments, but the need for this
convention is not clear to me at all.

Anyone see the benefits?

解决方案

What is the convention if a previously protected/private method is ''promoted''
to public? Search-and-replace name change?

Derek wrote:


The company where I work uses a naming convention that I have
never used before. They use mixed-case letters for public
member functions, but lower-case with underscores for the
rest, like this:

class Foo
{
public:
void somePublicMemberFunction();
protected:
void hello_i_am_protected();
private:
void this_one_is_private();
};

The other developers swear that this convention makes code
easier to understand, but not one of can give me a concrete
justification.

Incidentally, in my previous jobs I always used the same
convention for all member functions quite happily, but after
several months of using this new one I''m still not convinced
it adds value.

I understand that private *data* members deserve a trailing
underscore or m_ prefix to differentiate them from local
variables or function arguments, but the need for this
convention is not clear to me at all.

Anyone see the benefits?



--
Bret Pehrson
mailto:br**@infowest.com
NOSPAM - Include this key in all e-mail correspondence <<38952rglkwdsl>>


"Derek" <me@nowhere.special.com> wrote...

The company where I work uses a naming convention that I have
never used before. They use mixed-case letters for public
member functions, but lower-case with underscores for the
rest, like this:

class Foo
{
public:
void somePublicMemberFunction();
protected:
void hello_i_am_protected();
private:
void this_one_is_private();
};

The other developers swear that this convention makes code
easier to understand, but not one of can give me a concrete
justification.
Naming conventions are intended to give the reader a way to
quickly understand something about the symbol, in your case it
is probably the fact that the function is (a) a member and (b)
a public or private/protected one. If in your project the
access rights to the symbol make such a difference as to
justify having a different naming convention for the functions,
then the difference is only known to those who are involved in
the project...
Incidentally, in my previous jobs I always used the same
convention for all member functions quite happily, but after
several months of using this new one I''m still not convinced
it adds value.
Then you have to talk to those who established such naming
convention. And unless one of your colleagues reads this NG
as well, you''re better off off-line. Without seeing more
of the code or even working on it for some time, how could
any of us successfully guess the intentions of the author
of the convention?
I understand that private *data* members deserve a trailing
underscore or m_ prefix to differentiate them from local
variables or function arguments, but the need for this
convention is not clear to me at all.

Anyone see the benefits?



I can''t say that I''ve _used_ such convention, but there is
probably something there, otherwise why would people keep
using it? But, alas, I can''t say I see it. :-)

V


Bret Pehrson wrote:

What is the convention if a previously protected/private
method is ''promoted'' to public? Search-and-replace name
change?



Yup. Elegant, isn''t it? :)


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

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