High-Quality Routines(2)

How to Use Routine Parameters
1. Put parameters in input-modify-output order
Instead of ordering parameters randomly or alphabetically, list the parameters that are input-only first, input-and-output second, and output-only third.
2. If several routines use similar parameters, put the similar parameters in a consistent order.
3. Use all the parameters.
If you pass a parameter to a routine, use it. If you aren't using it, remove the parameter from the routine interface.
4. Don't use routine parameters as working variables.
5. Document interface assumptions about parameters.
If you assume the data being passed to your routine has certain characteristics, document the assumptions as you make them.
The kind of interface assumptions about parameters we should document:
    Whether parameters are input-only, modified, or output-only.
    Units of numeric parameters(inches, feet,meters and so on)
    Meaning of status codes and error values if enumerated type aren't used.
    Rangers of expected values.
    Specific values that shoudl never appear.
6. Limit the number of a routine's parameters to about seven.
7. Consider an input, modify, and output naming convention for parameters.
8. Pass the variables or objects that the routine needs to maintain it's interface abstraction.
If a routine need 3 paramethers that include in an object, pass the 3 parameters or the entire object?
To solve the problem, think that what abstraction is presented by the routine's interface?
    If the abstraction is that the routine expects you to have 3 specific data elements, and it is only a coincidence that those 3 elements happend to be provided by the same object, then you should pass the 3 specific data individually.
    If the abstraction is that you will always have that particular object in hand and the routine will do something or other with that object, then you truly do break the abstraction when you expose the 3 specific data elements.
9. Don't assume anything about the parameter-passing mechanism.
10. Make sure actual parameters match formal parameters.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值