分類: c/c++
qt 2011-05-01 12:03
1723人閱讀收藏
舉報 如果它使你的**看起來不好,你可以打破任何乙個規則。
// wrongint a, b;
char *c, *d;
// correct
int height;
int width;
char *nameofthis;
char *nameofthat;
// wrong在qt例子編寫中,對變數名有如下建議:short cntr;
char item_delim = '/t';
// correct
short counter;
char itemdelimiter = '/t';
void myclass::setcolor(const qcolor &color;)或
void myclass::setcolor(const qcolor &newcolor;)避免使用(意義不明確的字元):
void myclass::setcolor(const qcolor &c)注意:在建構函式中,會遇到同樣的問題。但無論你信與不信,下面的可以工作
myclass::myclass(const qcolor &color;): color(color)
// wrongif(foo)
// correct
if (foo)
char *x;const qstring &mystring;
const char * const y = "hello";
// wrongchar* blockofmemory = (char* ) malloc(data.size());
// correct
char *blockofmemory = reinterpret_cast(malloc(data.size()));
//wrongx = rect.x();
y = rect.y();
width = rect.width();
height = rect.height();
// wrongif (codec)
// correct
if (codec)
class moo;
// wrongif (address.isempty())
// correct
if (address.isempty())
return false;
if (x)
// correctif (address.isempty() || !isvalid()
|| !codec)
// wrongif (address.isempty())
return false;
else
// correct
if (address.isempty()) else
// wrong
if (a)
if (b)
...else
...// correct
if (a)
// wrongwhile (a);
// correct
while (a) {}
// wrongif (a && b || c)
// correct
if ((a && b) || c)
// wrong
a + b & c
// correct
(a + b) & c
switch (myenum)
// correctif (longexpression
+ otherlongexpression
+ otherotherlongexpression)
//wrong對 whle 或else if,不存在這個問題:if (dsfljfsfskjldsjkljklsjdk
&& fdsljsjdsdljklsjsjkdfs
&& dsfljkdfjkldksdfjdjkfdksfdkjld)
//correct
if (dsfljfsfskjldsjkljklsjdk
&& fdsljsjdsdljklsjsjkdfs
&& dsfljkdfjkldksdfjdjkfdksfdkjld)
while (dsfljfsfskjldsjkljklsjdk&& fdsljsjdsdljklsjsjkdfs
&& dsfljkdfjkldksdfjdjkfdksfdkjld)
Qt編碼風格
如果它使你的 看起來不好,你可以打破任何乙個規則。wrong int a,b char c,d correct int height int width char nameofthis char nameofthat wrong short cntr char item delim t correc...
QT編碼風格
如果它使你的 看起來不好,你可以打破任何乙個規則。wrong int a,b char c,d correct int height int width char nameofthis char nameofthat wrong short cntr char item delim t correc...
Qt編碼風格
如果它使你的 看起來不好,你可以打破任何乙個規則。wrong int a,b char c,d correct int height int width char nameofthis char nameofthat wrong short cntr char item delim t correc...