Don’t modify input parameters.

It will lead to unexpected results later.

When a long routine has input parameters, they carry a certain meaning. The variable boxWeight is expected to represent the weight of the box.

If a new developer is editing the code and is working towards the end of the routine, they expect boxWeight to still represent the weight of the box.

The problem here is that if the input parameters are modified at some point in the routine, they will no longer represent their original values. Then, developers who come later may be operating under some false assumptions. This then leads to severe bugs in logic, that aren’t easily caught.

So don’t modify input parameters. Instead, use local variables.

newWeight = boxWeight * 1.1;

This way the original parameter retains its value throughout the scope.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: