HIGH-Quality Routines (2)

xiaoxiao2021-03-06  55

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 am'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.

The Kind of Interface Assumptions About Parameters We Should Document:

WHETER parameters is input-only, modified, or output-only.

Units of Numeric Parameters (inches, feet, meters and so on)

Meaning of status cots and error valueness if enumerated type aren 'ket.

Rangers of expertted value.

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 Abstract.

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 Abstract 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. Do not assume anything about The parameter-passing mechanism.

10. Make Sure Actual Parameters Match Formal Parameters.

转载请注明原文地址:https://www.9cbs.com/read-113885.html

New Post(0)