Just go ahead and multiply

You have some probabilities: 70% chance a consumer will want to go to a store of type x, and 30% the consumer wants to go to a store of type y. you have some mechanism in place to take these percentages and cause them to result in the appropriate proportion of actions.

But what if there is no store of type x? Just write a function that returns one if a store of that type exists, and zero if it does not. Then multiply the percentage times that return value.

You need the function anyway, so that is no overhead. But you might be tempted to write an if statement that zeroes out the % value when the type of store in question does not exist.

In general, simply going ahead and multiplying, even if you are only multiplying by one, makes for tidier, easier to maintain code.

Don't unnecessarily multiply entities! (The conditional statement being a new, unnecessary entity.)

No comments:

Post a Comment