Discussion on the programming style 6

Source: Internet
Author: User
Tags goto

VI. Modular Specification:

In order to improve the reusability of software, the workload of repetitive development is reduced. At the same time, in order to improve the readability of the program and facilitate the maintenance of the program, the modularization of the software must be strengthened. Modularity should follow these basic specifications:

1, a function should be fine and small, the function of the code should be controlled in a modest scale, the code for each function can not be more than 150 lines, if more than this size, should be modular work. For some special functions that do take more than 150 lines, they should be submitted for discussion, after which the writer is asked to comment on the function in more detail, and to specify the reason for the function Super row, as well as design ideas.

2, a certain function, if repeated implementation of more than three times, should consider the modular, write it as a common function. and publish it to the developer. and requires the interface document and implementation of the functions of the record.

3. Each developer should use the ready-made modules of others as much as possible to reduce the duplication of development.

4, the function of the modular, to consider the function of the hierarchical relationship, especially in the addition of new functional modules, the original function code to be carefully adjusted to do the same function of the different functions do not have duplicate code, this requirement is to facilitate code maintenance. Examples are as follows:

The following functions exist:

//从szFileName文件中取 ......
long ...... cmGetSomething(const char * c_szFileName,......)
{
CFile * pFile;//用来保存打开文件的地址
pFile=new CFile(c_szFileName,CFile::modeRead);//用创建一个只读文件
if(pFile==NULL)
{
lResult=CM_POINT_IS_NULL;
goto END;
}
//从文件中读取......
......
//关闭文件
delete pFile;
END:
return lResult;
}

If you need to add a new function for the following interface now:

long ...... cmReadSomething(CFile * pFile)
{
if(pFile==NULL)
{
lResult=CM_POINT_IS_NULL;
goto END;
}
//从文件中读取......
......
END:
return lResult;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.