C ++编程风格指南 [英] C++ Programming Style Guidelines

查看:101
本文介绍了C ++编程风格指南的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

C ++编程风格指南

http:// geosoft .no / development / cppstyle.html

我认为这些指南几乎都是错误的。

例如:


11.私有类变量应该有下划线后缀。

class SomeClass {

private:

int length_ ;

}


12.通用变量的名称应与其类型相同。

void setTopic(Topic * topic)

// NOT:void setTopic(Topic * value)

// NOT:void setTopic(Topic * aTopic)

// NOT: void setTopic(主题* x)


void connect(数据库*数据库)

// NOT:void connect(Database * db)

// NOT:void connect(Database * oracleDB)


7.必须使用get / set术语

其中直接访问属性。

employee.getName(); matrix.getElement(2,4);

employee.setName(name); matrix.setElement(2,4,value);

C++ Programming Style Guidelines

http://geosoft.no/development/cppstyle.html

I think that these guidelines are almost *all* wrong.
For example:

11. Private class variables should have underscore suffix.
class SomeClass {
private:
int length_;
}

12. Generic variables should have the same name as their type.
void setTopic (Topic *topic)
// NOT: void setTopic (Topic *value)
// NOT: void setTopic (Topic *aTopic)
// NOT: void setTopic (Topic *x)

void connect (Database *database)
// NOT: void connect (Database *db)
// NOT: void connect (Database *oracleDB)

7. The terms get/set must be used
where an attribute is accessed directly.
employee.getName(); matrix.getElement (2, 4);
employee.setName (name); matrix.setElement (2, 4, value);

推荐答案



" E. Robert Tisdale <,E ************** @ jpl.nasa.gov>。在消息中写道

news:d8 ********** @ nntp1.jpl.nasa.gov ...

"E. Robert Tisdale" <E.**************@jpl.nasa.gov> wrote in message
news:d8**********@nntp1.jpl.nasa.gov...
C ++编程风格指南
http://geosoft.no/development/cppstyle.html

我认为这些指南几乎都是错误的。
例如:

11.私有类变量应该有下划线后缀。
class SomeClass {
private:
int length_;
}
12.通用变量的名称应与其类型相同。
void setTopic(主题*主题)
// NOT:void setTopic(主题*值)
// NOT:void setTopic(主题* aTopic)
// NOT:void setTopic(Topic * x)

void connect(数据库*数据库)
// NOT:void connect(Database * db)
// NOT:void connect(Database * oracleDB)
直接访问属性。
employee.getName(); matrix.getElement(2,4);
employee.setName(name); matrix.setElement(2,4,value);
C++ Programming Style Guidelines

http://geosoft.no/development/cppstyle.html

I think that these guidelines are almost *all* wrong.
For example:

11. Private class variables should have underscore suffix.
class SomeClass {
private:
int length_;
}

12. Generic variables should have the same name as their type.
void setTopic (Topic *topic)
// NOT: void setTopic (Topic *value)
// NOT: void setTopic (Topic *aTopic)
// NOT: void setTopic (Topic *x)

void connect (Database *database)
// NOT: void connect (Database *db)
// NOT: void connect (Database *oracleDB)

7. The terms get/set must be used
where an attribute is accessed directly.
employee.getName(); matrix.getElement (2, 4);
employee.setName (name); matrix.setElement (2, 4, value);




我绝对不同意#7。我可能是新手,但我很确定这违反了OOD的基本原则之一:多态性。当你可以超载它时,为什么要为函数使用两个

名称?


employee.Name(); matrix.Element(2,4);

employee.Name(name); matrix.Element(2,4,value);


Dave



I definitely don''t agree with #7. I may be new to this, but I''m pretty sure
this violates one of the basic principles of OOD: polymorphism. Why use two
names for a function when you can overload it?

employee.Name(); matrix.Element(2, 4);
employee.Name(name); matrix.Element(2, 4, value);

Dave




" E 。 Robert Tisdale

"E. Robert Tisdale"
C ++编程风格指南

http://geosoft.no/development/cppstyle.html

我认为这些指南几乎都是错误的。
例如:

11.私有类变量应该有下划线后缀。
class SomeClass {
private:
int length_;
}


它没有说为什么不与所有班级成员一起做这个,我不知道

的原因。
7.条款获取/设置必须使用
直接访问属性。
employee.getName(); matrix.getElement(2,4);
employee.setName(name); matrix.setElement(2,4,value);
C++ Programming Style Guidelines

http://geosoft.no/development/cppstyle.html

I think that these guidelines are almost *all* wrong.
For example:

11. Private class variables should have underscore suffix.
class SomeClass {
private:
int length_;
}
It doesn''t say why not to do this with all class members and I don''t know a
reason.
7. The terms get/set must be used
where an attribute is accessed directly.
employee.getName(); matrix.getElement (2, 4);
employee.setName (name); matrix.setElement (2, 4, value);




函数有不同的用途,所以我同意给它们不同的

名字。


弗雷泽。



The functions have different purposes so I agree with giving them different
names.

Fraser.




" David Lee Conley" <共******** @ earthlink.net>在消息中写道

news:ti **************** @ newsread3.news.atl.earthli nk.net ...

"David Lee Conley" <co********@earthlink.net> wrote in message
news:ti****************@newsread3.news.atl.earthli nk.net...

7.必须使用get / set术语
直接访问属性。
employee.getName(); matrix.getElement(2,4);
employee.setName(name); matrix.setElement(2,4,value);

7. The terms get/set must be used
where an attribute is accessed directly.
employee.getName(); matrix.getElement (2, 4);
employee.setName (name); matrix.setElement (2, 4, value);



我绝对不同意#7。我可能对此不熟悉,但我很确定这肯定违反了OOD的基本原则之一:多态性。当你可以重载它时,为什么
使用两个名字?

employee.Name(); matrix.Element(2,4);
employee.Name(name); matrix.Element(2,4,value);

戴夫



I definitely don''t agree with #7. I may be new to this, but I''m pretty
sure this violates one of the basic principles of OOD: polymorphism. Why
use two names for a function when you can overload it?

employee.Name(); matrix.Element(2, 4);
employee.Name(name); matrix.Element(2, 4, value);

Dave




我不同意。多态性与不同类型的对象有关

用自己的方法完成相同的任务,例如Rectangle和

Circle都执行Draw功能。任务是画画。他们如何做b $ b这样做有什么不同。这是通过覆盖虚拟

函数而不是通过重载来实现的。


(无论如何,这是运行时多态性。 s也是编译时

多态,使用模板,但同样,这与使用

不同类型有关,而不是让一个名字代表单个上的不同操作

类型。)


一个名为Name的函数什么都没告诉你......它不是一个动词,这通常是一个函数名称的b / b
。它应该告诉你它的作用。


另外,假设你想为你的函数设置一个默认参数?

你会在你的场景中实现这一目标吗?你不能,因为遗漏

名称(或值)参数突然改变了函数的含义

从setter到getter的调用。


如果你使用访问器功能,那么调用它们getWhatever和setWhatever

听起来对我来说是完全合理的要求。给他们只是成员变量的

名称不会。


-Howard




I disagree. Polymorphism has to do with objects of different types
accomplishing the same task with their own methods, such as a Rectangle and
a Circle both performing a Draw function. The task is to"draw". How they
do it is what differs. And that''s accomplished by overriding virtual
functions, not by overloading.

(That''s run-time polymorphism, anyway. There''s also compile-time
polymorphism, using templates, but again, that has to do with working with
different types, not making one name stand for different actions on a single
type.)

A function called "Name" tells you nothing... it''s not a verb, which is what
a function name should usually be. It should tell you what it does.

Also, suppose you want to have a default parameter for your function? How
would you accomplish that in your scenario? You can''t, because leaving out
the name (or value) parameter suddenly changes the meaning of the function
call from a setter to a getter.

If you use accessor functions, then calling them getWhatever and setWhatever
sound like perfectly reasonable requirements to me. Giving them just the
name of the member variable does not.

-Howard



这篇关于C ++编程风格指南的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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