nac*_*o4d 58 c++ naming-conventions
我来自Objective-C和Cocoa世界,那里有很多常规,许多人会说它让你的代码变得美丽!现在用C++编程我找不到像C++这样的好文档.
标准C++可能没有上面的内容,但我希望我可以坚持使用其他一些SDK或API(如Microsoft的(?)等)约定.
我希望你能给我一些链接.
GMa*_*ckG 88
做任何你想做的事,只要它最小,一致,并且不违反任何规则.
就个人而言,我发现Boost风格最简单; 它与标准库匹配(给代码提供统一的外观)并且很简单.我个人分别为成员和参数添加前缀m和p前缀,给出:
#ifndef NAMESPACE_NAMES_THEN_PRIMARY_CLASS_OR_FUNCTION_THEN_HPP
#define NAMESPACE_NAMES_THEN_PRIMARY_CLASS_OR_FUNCTION_THEN_HPP
#include <boost/headers/go/first>
#include <boost/in_alphabetical/order>
#include <then_standard_headers>
#include <in_alphabetical_order>
#include "then/any/detail/headers"
#include "in/alphabetical/order"
#include "then/any/remaining/headers/in"
// (you'll never guess)
#include "alphabetical/order/duh"
#define NAMESPACE_NAMES_THEN_MACRO_NAME(pMacroNames) ARE_ALL_CAPS
namespace lowercase_identifers
{
class separated_by_underscores
{
public:
void because_underscores_are() const
{
volatile int mostLikeSpaces = 0; // but local names are condensed
while (!mostLikeSpaces)
single_statements(); // don't need braces
for (size_t i = 0; i < 100; ++i)
{
but_multiple(i);
statements_do();
}
}
const complex_type& value() const
{
return mValue; // no conflict with value here
}
void value(const complex_type& pValue)
{
mValue = pValue ; // or here
}
protected:
// the more public it is, the more important it is,
// so order: public on top, then protected then private
template <typename Template, typename Parameters>
void are_upper_camel_case()
{
// gman was here
}
private:
complex_type mValue;
};
}
#endif
Run Code Online (Sandbox Code Playgroud)
那.(就像我在评论中已经说过了,千万不能采用谷歌风格指南为您的代码,除非它是无关紧要的命名约定的东西.)
Mat*_* M. 27
可能存在与个体一样多的命名约定,辩论与使用哪种支撑样式等无穷无尽(并且无菌).
所以我会有两个建议:
剩下的由你决定.
Phi*_*ipp 18
我实际上经常使用Java样式:PascalCase用于类型名称,camelCase用于函数和变量,CAPITAL_WORDS用于预处理器宏.我更喜欢Boost/STL约定,因为你没有后缀类型_type.例如
Size size();
Run Code Online (Sandbox Code Playgroud)
代替
size_type size(); // I don't like suffixes
Run Code Online (Sandbox Code Playgroud)
这具有StackOverflow代码格式化程序识别Size为类型名称的额外好处;-)
| 归档时间: |
|
| 查看次数: |
96934 次 |
| 最近记录: |