本文介绍了C ++编程风格指南的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 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.htmlI 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 usedwhere 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); DaveI definitely don''t agree with #7. I may be new to this, but I''m pretty surethis violates one of the basic principles of OOD: polymorphism. Why use twonames for a function when you can overload it?employee.Name(); matrix.Element(2, 4);employee.Name(name); matrix.Element(2, 4, value);Dave 函数有不同的用途,所以我同意给它们不同的 名字。 弗雷泽。The functions have different purposes so I agree with giving them differentnames.Fraser. 我绝对不同意#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 听起来对我来说是完全合理的要求。给他们只是成员变量的 名称不会。 -HowardI disagree. Polymorphism has to do with objects of different typesaccomplishing the same task with their own methods, such as a Rectangle anda Circle both performing a Draw function. The task is to"draw". How theydo it is what differs. And that''s accomplished by overriding virtualfunctions, not by overloading.(That''s run-time polymorphism, anyway. There''s also compile-timepolymorphism, using templates, but again, that has to do with working withdifferent types, not making one name stand for different actions on a singletype.)A function called "Name" tells you nothing... it''s not a verb, which is whata function name should usually be. It should tell you what it does.Also, suppose you want to have a default parameter for your function? Howwould you accomplish that in your scenario? You can''t, because leaving outthe name (or value) parameter suddenly changes the meaning of the functioncall from a setter to a getter.If you use accessor functions, then calling them getWhatever and setWhateversound like perfectly reasonable requirements to me. Giving them just thename of the member variable does not.-Howard 这篇关于C ++编程风格指南的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-20 17:22