Chinaunix首页 | 论坛 | 博客
  • 博客访问: 266721
  • 博文数量: 55
  • 博客积分: 2030
  • 博客等级: 大尉
  • 技术积分: 737
  • 用 户 组: 普通用户
  • 注册时间: 2006-04-13 18:06
文章分类

全部博文(55)

文章存档

2011年(2)

2010年(7)

2009年(17)

2008年(29)

我的朋友

分类: C/C++

2008-09-24 01:14:27

Programming sytle:
Name: informative, concise, memorable, pronounceable if possible
Use descriptive names for globals:
 

int npending = 0;

short names for locals: npoints , not numberOfPoints
i, j loop indices, p, q for pointers, s, t for strings
begin with p for pointer, initial capital letters for Globals, all capitals for CONSTANS

Use active names for functions:

date.getTime()

Fuction that return a boolean value should be named so that the return value is unambiguous

? if (checkoctal(c))
if (isoctal(c))

 
Magic numbers are the constants, array sizes, character positions, conversion factors, and other literal numeric values that appear in programs
 

enum {
    MINROW    = 1,        /* top edge */
    MINCOL    = 1,        /* left edge */
    HEIGHT    = MAXROW -4    /* height of bars */
};

Define numbers as constants, not marcros
C++:const int MAXROW = 24;
C: enum {MAXROW = 24};

Don't belabor the obvious
Comment functions and global data


 

阅读(1426) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~