True is the contrary of false. Up is the opposite of down. What is the contrary of dog?

If you replied “cat”, what exactly makes cats the the contrary of dogs the same way up is the contrary of down?

*

I usage this example to point out a common problem that software developers make with variable and parameter names. When there space two feasible values for part variable or parameter, that is an extremely common the it should be identified as a boolean type.For example, a parameter can be called foobarEnabled and a True or False worth is passed for it. This makes sense. The foobar is either permitted or disabled. “Not enabled” has a distinct and unambiguous the opposite value, “disabled”. A boolean below makes perfect sense.

You are watching: The opposite of down and the opposite of cat

However, there is additionally a situation when the two (and only two) possible values room not have to opposites. In this case, a boolean value is the not correct data type to use. On a recent web application I was working on, there is a kind that has an “add foo” and also “edit foo” mode, depending upon whether the widget is including a new foo or editing and enhancing an present foo (they usage pretty much the same kind fields, but the backend demands to understand for technological reasons.)

To differentiate in between them, the duty that handles this type has an isAddMode parameter. If the form was it is registered in include mode, a True worth is passed to this parameter. If the kind was submitted in edit mode, a False worth is passed to this parameter. Understanding that “add” and “edit” room the just two values, this renders sense to the programmer creating this code. (But then again, programmers always think the password they themselves write renders sense.)

But from the perspective of one more programmer who needs to maintain this password later, this is the fully wrong name and data kind for this parameter. Having “not add mode” does not instinctively convey “edit mode” the same way “not enabled” conveys “disabled”.

Dog is no the opposite of cat.

The correct surname for a parameter favor this would be something like “mode” or “addOrEditMode” depending on how verbose you desire to be. The exactly data kind for a parameter prefer this is an enum form with two values for “add” and also “edit”.It may seem choose a trivial detail, yet making your password as readable together English is a an essential to having actually cleanly composed code i m sorry is easy to understand and also easy come debug.

See more: Cutest Girls On Instagram To Follow 2021, Instabumpic

(By the way, if friend would choose to know what the contrary of “cat” is, it’s “triceratops”.)


Learn to regime with my books for beginners, totally free under a an innovative Commons license:

*
*
*
*
*
*
*

Take my Automate the Boring Stuff through Python virtual Udemy course. Use this link to apply a 60% discount.