High-Quality Routines(1)

原创 2004年09月22日 18:44:00

What is a "routine"?
A routine is an individual method or procedure invocable for a  single purpose.

What is a high-quality routine?
It's a difficult question because it may include many features such  as:
1. has a good name
2. has good document.
3. have good layout.
4. doesn't read or write the global variables.
5. has a single purpose.
6. defends itself against bad data.
7. doesn't use magic number.
8. has appropriate parameters.

Reason to Create a Routine:
1. Reduce complexity.
2. Make a section of code readable.
Putting a section of code into a well-named routine is one of the best ways to document its purpose.
3. Avoid duplicate code.
4. Hide sequences
It's a good idea to hide the order in which events happen to be processed. WHY???
5. Improve protability.
6. Simplify complicated boolean tests.
Understanding complicated boolean tests in detail is rarely necessary for understanding program flow. Putting such a test into a function makes the code more readable.
7. Improve performance.

One of the strongest mental blocks to creating effective routines is a reluctance to create a simple routine for a simple purpose. Constucting a whole routine to contain two or three lines of code might seem like overkill. But experience shows how helpful a good small routine can be. First, it improves the readable. Second, the small operation tend to turn into larger operations.

Good Routine Names
1. Describe everything the routine does.
2. Avoid meaningless or wishy-washy verbs.
Routine names like HandleCalculation(), PerformServices(), ProcessInput() don't tell you what the routines do.
3. Make names of routines as long as necessary.
Research shows that the optimum average length for a variable name is 9 to 15 characters.
4. To name a function, use a description of the return value
Such as cos(), getColor(), isReady()
5. To name a procedure, use a strong verb followed by an object.
6. Use opposite precisely.
such as add/remove, begin/end, first/last, get/put.

Type of Cohesion
1. Functional cohesion
Is the strongest ad best kind of cohesion, occurring when a routine performs one and only one operation.
2. Sequential cohesion
Exists when a routine contains operations that must be performed in a specific order, that share data from step to step, and that don't make up a complete function when done together.
3. Communicational cohesion
Occurs when operation in a routine make use of the same data and aren't related in any other way.
4. Temporal cohesion
Occurs when operations are combined into a routine because they are all done at the same time. Typical examples would be Startup().

The remaining kinds of cohesion are generally unacceptable.
5. Procedural cohesion
Occurs when operations in a routine are done in a specified order
6. Logical cohesion
Occurs when serveral operations are stuffed into the same rouitne and one of the operations is selected by a control flag that's passed in.
7. Coincidental cohesion
Occurs when the operations in a routine have no discernible relationship to each other.

High-Quality Routines(2)

How to Use Routine Parameters1. Put parameters in input-modify-output orderInstead of ordering param...
  • wangjiong
  • wangjiong
  • 2004年09月23日 14:47
  • 538

the thinker of code complete -- High-Quality Routines

1.名字尽量好,变量尽量少. 2.尽量实现子函数的内聚性. 3. 一定要判断函数的参数; 作为输入的参数,不要作为返回值,多申请一个变量; 多申请一个变量接受函数的返回值,再作判断. 重要一点不要...
  • u011370933
  • u011370933
  • 2013年12月29日 11:27
  • 467

SSLError: [Errno 1] _ssl.c:504: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate

安装tensorflowGPU版本时遇到的问题 SSLError: [Errno 1] _ssl.c:504: error:14090086:SSL routines:SSL3_GET_SERVER_...
  • wang2008start
  • wang2008start
  • 2017年08月03日 10:06
  • 593

[Code Complete] CH7 High-Quality Routines高质量子程序

1.       构造子程序的目的:是否需要的标准 Ø  降低复杂度:我们需要不停的抽象,忘记实现细节,使用抽象后的方法来编程。 Ø  引入中间、易懂的抽象:把很短的程序写成子程序的原因。 Ø ...
  • mumubaba
  • mumubaba
  • 2013年06月07日 02:09
  • 465

使用pip install 时出现[Errno 1] _ssl.c:504: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:ce,,

完整错误信息: There was a problem confirming the ssl certificate: [Errno 1] _ssl.c:504: error:14090086:SS...
  • krystollia
  • krystollia
  • 2014年01月17日 18:17
  • 4497

easy_install——error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed -- S

今天在安装python模块的时候, 出现一个问题:
  • yunjingguang
  • yunjingguang
  • 2014年08月15日 10:14
  • 3464

SSLError(SSLError(1, '_ssl.c:510: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:

关于pip版本的查看和更换pip版本 pip list 查看pip安装的包的版本 pip -V 查看pip本身的版本 easy_install pip=9.0.1 SSLError...
  • qq_36260310
  • qq_36260310
  • 2017年12月18日 11:11
  • 85

“error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed”解决方法

使用git通过https方式从github clone git repo源码时,报错如下: 1 2 3 Cloning into 'git'... ...
  • ee230
  • ee230
  • 2015年01月04日 14:08
  • 12664

_ssl.c:503: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

pingtest服务运行过程中发现无法访问银联网址。并且报错_ssl.c:503: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:ce...
  • emeitu
  • emeitu
  • 2017年01月23日 10:41
  • 344

用python发送QQ邮件遇到的错误记录(ssl.SSLError: [Errno 1] _ssl.c:504)

在学习《RabbitMQ实战》这本书,书中是代码为python语言,在用书中例子发送qq邮件时,遇到以下错误 报错信息:ssl.SSLError: [Errno 1] _ssl.c:504: e...
  • lvyuan1234
  • lvyuan1234
  • 2017年04月10日 14:49
  • 1422
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:High-Quality Routines(1)
举报原因:
原因补充:

(最多只允许输入30个字)