mercredi 27 octobre 2021

What is the design principle to only assign a single meaning to a boolean variable?

I'm pretty sure I was taught a long time ago that it's bad practice to use a boolean variable to hold information about more than one property. I've not been able to find the name of a design principle that covers this.

As an example, say we wanted to record whether a customer wanted milk and sugar in their drink. We'd have one variable for milk and one for sugar.

We wouldn't conflate these into variables milk&Sugar and milk&NoSugar because the choice of Sugar is in both variables, so what would it mean if both boolean variables were true? Does the customer want sugar or not?

But is there a name for this design principle?

(A colleague has tried to justify the latter, noting that this works if one boolean takes precedence over the other. Seniority rather than sense has prevailed!)

Aucun commentaire:

Enregistrer un commentaire