CC2e 术语:把 routine 译为“子程序”的理由

来源:互联网 发布:数学建模交通优化模型 编辑:程序博客网 时间:2024/04/29 13:53

   

  这里特别说明一下在《Code Complete(代码大全) 第二版》中我们把 routine 译为“子程序”的理由。(主要观点来自裘宗燕老师,部分文字取自裘老师写给我们的邮件。)

  这本书先讲整体的设计(第 5 章);而后讲 class(第 6 章),是下降一个层次;而后讲 routine(第 7 章)。在第 7 章“High-Quality Routines”的一开始,作者自设一问:

What is a “routine”? A routine is an individual method or procedure invocable for a single purpose. Examples include a function in C++, a method in Java,a function or sub procedure in Microsoft Visual Basic. For some uses, macros in C andC++ can also be thought of as routines. You can apply many of the techniques for creatinga high-quality routine to these variants.

非正式译文:何谓“routine”?routine 是具有单一目的、能单独调用的一段代码(method 或 procedure)。例如,C++ 中的函数 (function),Java 中的 method,Microsoft Visual Basic 中的 function 或 sub。某些情况下,C/C++ 中的宏 (macro) 也可以认为是 routine。

  可见作者口中的 routine 就是一段有名称、能调用的代码,可能有参数、也可能没有参数,可能有返回值、也可能没有返回值,实际指就是 subroutine(subroutine 是比较正式的说法)。如果这是一本针对 C/C++ 语言的书,那么作者多半会用“function/函数”这个词。而 CC2e 是一本针对一般软件开发的书,并非针对特定语言,作者一直非常谨慎地回避 function 这个词(一般只作“功能”讲)。如果细分起来,function 是有返回值的 routine,procedure(过程)是没有返回值的 routine,method 是作为 class 的成员的 routine,甚至 C++ 中重载了的运算符也算是 routine。

  书中也有讲函数的地方,讲的就是函数的返回值问题(函数的特殊问题),也有讲 method 的地方,讲的就是 method 的特殊问题。因此 routine 的译文应该能涵盖函数、过程、method 。这样想来,恐怕很难找到比“子程序”更好的词了。




原创粉丝点击