编程规范
1 格式规范,新的语句段落需要缩进,层次分明,整体结构应美观大方。如
for (int i = 0; i < numscans; i++)
{
int y1 = (i * iHeight) / numscans;
int y2 = ((i + 1) * iHeight) / numscans;
if (QuickScan)
y2 = Math.Min(y2, y1 + DEFAULTSTRIPWIDTH);
string sCodesRead = ReadBarcodes(bmp, y1, y2, direction, types);if ((sCodesRead != null) && (sCodesRead.Length > 0))
{
string[] asCodes = sCodesRead.Split('|');
foreach (string sCode in asCodes)
{
if (!CodesRead.Contains(sCode))
CodesRead.Add(sCode);
}break;
}
}
2 变量名,不可以用单纯的a,b,c,变量名应该和用途相结合,见名知意。
如max表示最大值,min表示最小值,maxX和maxY表示取得最大值的X和Y坐标,m_width和m_height表示图像的高度和宽度,col表示图像列方向上的系数。
int max=0,min=256;
int maxX=0,maxY=0;
int m_width=lpbi->biwidth;
for(col=0;col<=window;col++){}
3 变量名后要加注释,以表示其用途。如
BYTE *m_buf; //原始图像缓存
BYTE *afterFileter_buf; //去除噪声后的图像缓存
4 函数需要加注释,以表明其用途,注释格式如下,详细说明函数功能,参数含义,返回数字及作者等
//funciton: Turns an 8 bits gray scale to 2bits gray scal
/warning: Only the 8 bits gray scale image with 2 values (0 and 255) will be correctly turned!
//pDib:Points to the image 's DIB contains BITMAPINFOHEADER, PALETTE and pixels
//return: New pointer to new DIB if sucess, null if failed.
//author: lulu
void * WINAPI EightBitsGrayToTwoBits(void * pDib)
{
}