post Category: 书斋志 post postNovember 21, 2008



要小!100-300行最多

分块以及缩进对齐

一个函数只做一件事

每个函数实现一个级别的抽象即可

分离switch判定的逻辑

使用描述性的名称命名

函数的参数(越少越好,封装的越精炼越好)

传递单一形式的参数

不要传boolean参数

二元函数,不要穿重复,尽量少参数

三个参数就很难理解,也需要很多判断。

多余2-3个参数最好用对象

参数List

动词和关键字

函数要没有副作用,比如窜改了参数引用值等

函数输出参数

分离

返回错误代码

抽出try
catch
错误控制块

捕获错误的函数应该是单一的,也就是try
catch finally
的外部不要还有逻辑

不要重复自己(don’t
repeat yourself

结构化编程

 

Sorry, no comments yet.

Write Your Comment

Comment Guidelines: Basic XHTML is allowed (a href, strong, em, code). All line breaks and paragraphs will be generated automatically.

You should have a name, right? 
Your email address, I promised I won't tell it to anyone. 
If you have a web site or blog, you can type the URL right here. 
This is where you type your comments. 
Remember my information for the next time I visit.