NAMES:
Always name your classes ,variables and functions with the greatest care,and explain them thoroughly.
编译时命名需要符合标示符规则,且不要与程序所拥有的固定标示符重复,区分大小写,并且注意不要太过难以区分导致程序的不简便。
DOCUMENTATION & FORMAT:
Keep your documentation concise but descriptive.
文档的存在不止方便其他人读懂理解这个程序,也帮助了自己对于自己编写的这个程序的记忆与细节化,因此记录时应简洁明确。
1.Stubs:
To compile the main program correctly ,there must be something in the place of each function that is used, and hence we must put in short ,dummy functions,called stubs.
2.Definition of the class Life:
Each Life object needs to include a rectangular array, which we shall call grid ,to store a Life configuration. We use an integer entry of 1 in the array grid to denote a living cell,and 0 to denote a dead cell. Hence ,the class Life should include a member function neighbor_count that does this task.
3.Counting Neighbors:
The function that counts neighbors of the cell with coordinates row, col requires that we look in the eight adjoining cells.
4.Sentinel:
Another term often used instead of hedge is sentinel:A sentinel is an extra entry put into a data structure so that boundary conditions need not be treated as a special case.
5.Updating the grid:
We first use the data stored in the configuration to calculate entries of a rectangular array called new_grid that records the updated configuration.We then copy new_grid,entry by entry,back to the grid member of our Life object.
6.Input & output:
It now remains only to write the Life methods initialize() and print(), with the functions user_says_yes() and instructions() that do the input and output for our program.
Instructions()
A simple exercise in use of the put to operator<<and the standard output stream called cout.
Initialization
The Life method initialize() must accomplish is to set up an initial configuration.
7.Divers
驱动器是一种用于测试和调试程序的辅助函数,可以输入并评价此函数。
8.Program Tracing
程序跟踪使得编程更加严谨,完成编译后,再次检查此程序,发现潜在的缺陷,然后改进。
9.Principles of program testing
测试数据的质量比数量更重要。
本文详细介绍了程序设计过程中的核心原则,包括命名规范、文档编写、函数与类的设计等,并探讨了程序测试的重要性和方法。此外,还提到了程序跟踪和调试的技巧。

765

被折叠的 条评论
为什么被折叠?



