您的位置:首页 > 编程语言 > C语言/C++

Summarizes chapter one of datastructures and program design in C++

2013-08-20 20:54 651 查看
Summarizes chapter one of datastructures and program design in C++

The chapter one has summarizes importantprinciples of good programming aim at large projects, and introduces somemethods for discovering effective algorithms.

First, the problems of large program arethat depends on the basic tasks. Each part of large program must be wellorganized, clearly written, and thoroughly understand.

We shall distinguish between methods andfunctions as convention: Methods of a class are public. Functions in a classare private.

Second, summarizes some good program as follow:

Programming Precept:

☆ Include precise preconditionsand post conditions with every program, function, and method that you write. (Asimilar list should be including with every program, function, or method.)

☆ Always name your classes,variables and functions with the greatest care, and explain them thoroughly.(The careful choice of name can go a long way in clarifying a program and in helping to avoid misprints and common errors.)

☆ Keep your documentation concisebut descriptive.

▪Place a program at thebeginning of each function.

▷Identification

▷Statement of the purpose of thefunction and algorithm used.

▷The changes the function makesand what data it uses,

▷Reference to furtherdocumentation external to the program.

▪When each variable, constant,or class is declared, explain what it is and how it is.

▪Introduce each significantsection, paragraph and function of the program with a comment stating brieflyits purpose or action.

▪Indicate the end of each significantsection if it is not otherwise obvious.

▪Avoid comments that parrot whatthe code does or that meaningless jargon.

▪Explain any statement thatemploys a trick or whose meaning is unclear.

▪The code itself should explain howthe program works. The documentation should explain why it works and what itdose.

▪Whenever a program is modified,be sure that the documentation is corresponding modified.

▪The reading time for programsis much more than the writing time. Make reading easy to do.

☆ Don’t lose sight of the forestfor its tree.

☆ Use classes to model thefundamental concepts of the program. (The verbs that we use will often signifythe important functions.)

☆ Each function should do onlyone task, but do it well. (The function itself will undoubtedly contain manydetails, but they not appear until the next stage of refinement.)

☆ Each class or function shouldhide something. (we should practice information hiding.)

☆ Keep your connections simple. Avoidglobal variables whenever possible.

Never cause side effects if you can avoidit. If you must use global variables as input, document them thoroughly.

☆ Keep your input and output asseparate functions, so they can be changed easily and can be custom tailored toyour computing system.

☆ The quality of test data ismore important than its quantity. Program testing can be used to show thepresence of bugs, but never their absence.

☆ Testing methods: There are atleast three general philosophies that are used in the choice of test data. TheBlack-Box Method, The Glass-Box Method, the Ticking-box Method.

☆ For a large and importantprogram, more than half the work comes in the maintenance phase, after it hasbeen completely debugged, tested, and put into use.

☆ Be sure you understand your problem completely. If you must change its terms, explain exactly what you have down.

☆ Design the user interface withthe greatest care possible. A program’s success depends greatly.

☆ Do not optimize you code unless it isnecessary to do so. Do not start to optimize code until it is complete andcorrect. Most programs spend 90 percent of their time doing 10 percent of theirinstructions. Find this 10 percent, and concentrate your
efforts for efficiency there

☆ Keep your algorithms as youcan. When in doubt, choose the simple way.

☆ Sometimes postponing problemssimplifies their solution.

☆ Never code until thespecifications are precise and complete.

☆ Act in haste and repent atleisure. Program in haste and debug forever.

☆ Starting afresh is often easierthan patching an old program.

☆ Always plan to build aprototype and throw it away. You’ll do so whether you plan to or not.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐