Good Routines Names
1.描述子程序所做的所有事情。(尽量不要编写产生副作用的子程序)
2.避免使用无意义的、模糊地或表述不清的动词。例:HandleOutput()改为FormatAndPrintOutput()
3.不要仅通过数字来形成不同的子程序名字。
4.根据需要确定子程序名字的长度。
5.给函数命名是要对返回值有所描述。例:cos(),customerID.next(),printer.IsReady()和pen.CurrentColor()
6.给过程起名时使用预期强烈的动词加宾语的形式。例:PrintDocument(),CalcMonthlyRevenues()(计算每月收入),CheckOrderInfo()(查询订单信息),
RepaginateDocument()
在面向对象中,不用再过程中加入对象的名字(宾语),因为对象本身已经包含在调用语句中了。
例:Document.Print(),OrderInfo.Check(),MonthlyRevenues.Calc()。
如果Check类是从Document类继承而来的,那么check.print()表示打印一张支票。而check.PrintDocument()表示打印支票薄或信用卡账单。
7.准确使用对仗词
add/remove increment/decrement(增长/消耗) open/close begin/end insert/delete(插入/删除)
show/hide(显示/隐藏) create/destroy(创建/销毁) lock/unlock(锁定/解锁) source/target(源/目标) first/last
min/max start/stop get/put next/previous(下一个/上一个) up/down get/set old/new
8.为常用操作确立命名规则