通过伪代码进行子程序设计

来源:互联网 发布:淘宝购买快递单号 编辑:程序博客网 时间:2024/06/05 17:31

一段经典的伪代码:

    Keep track of Current Number of resources in use

       If another resource is available

           Allocate a dialog box structure

          If a dialog box structure could be allocated

                  Note that one more resource is in use

                 Initialize the resource

                 store the resource number at the location at the location provided by the caller

          Endif

       Endif

return true if  a new resource was created; else return false;

从以上的示例可以看出:

 1. 伪代码避免使用特定编程语言的元素,尽量少涉及其特定的内容

  2. 应该从一个略高于具体的编码实现的层次上去实现伪代码过程

  3. 其需要反复迭代精化的过程

呵呵,在读到为子程序命名的时候,我已经知道这是第若干次读到该如何命名的叙述了,只不过这次是针对

子过程的罢了;其中有一个需要警醒:通过来说,命名应该是清晰、无歧义的,如果你在起名字的时候犯难,

通常而言就表示这个子程序的目标还没明确。如果你看一个子程序却无法了解或者确认其具体的含义,那说明

这个是一个需要改进的设计,至少这是一个警告的信号。说到底,伪代码就是希望清晰、简洁地描述子程序的

处理过程,可以完整表述该子程序所要实现的操作和过程。

 

 

原创粉丝点击