True is the opposite of false. Up is the oppowebsite of down. What is the opposite of dog?
If you responded “cat”, what exactly renders cats the opposite of dogs the same means up is the opposite of down?
I usage this example to allude out a common difficulty that software program developers make via variable and parameter names. When there are 2 possible worths for some variable or parameter, it is very common that it should be defined as a boolean type.For example, a parameter might be called foobarEnabled and also a True or False value is passed for it. This provides feeling. The foobar is either permitted or disabled. “Not enabled” has actually a unique and also unambiguous oppowebsite worth, “disabled”. A boolean below renders perfect feeling.
You are watching: Opposite of down and opposite of cat
However, tbelow is additionally a situation as soon as the two (and only two) possible worths are not necessarily opposites. In this case, a boolean worth is the wrong data kind to use. On a recent web application I was functioning on, tbelow is a type that has an “include foo” and “modify foo” mode, depending upon whether the widget is including a new foo or modifying an existing foo (they usage pretty a lot the exact same form fields, yet the backend needs to understand for technological factors.)
To differentiate between them, the feature that handles this create has actually an isAddMode parameter. If the develop was submitted in Add mode, a True value is passed to this parameter. If the develop was submitted in Edit mode, a False worth is passed to this parameter. Knowing that “add” and also “edit” are the only two values, this renders sense to the programmer creating this code. (But then aget, programmers constantly think the code they themselves compose renders feeling.)
But from the perspective of one more programmer who has to preserve this code later, this is the completely wrong name and also data form for this parameter. Having “not add mode” does not instinctively convey “modify mode” the exact same way “not enabled” conveys “disabled”.
Dog is not the oppowebsite of cat.
The correct name for a parameter prefer this would be something like “mode” or “addOrEditMode” relying on how verbose you want to be. The correct data form for a parameter like this is an enum type through two worths for “add” and also “edit”.It may seem prefer a trivial detail, however making your code as readable as English is a vital to having actually cleanly composed code which is simple to understand and straightforward to debug.
See more: How To Make Lip Gloss Stay On Longer, The Secret Behind Lip Gloss That Stays On All Day
(By the method, if you would prefer to understand what the opposite of “cat” is, it’s “triceratops”.)
Discover to program with my books for beginners, complimentary under a Creative Commons license:
Take my Automate the Boring Stuff through Python digital Udemy course. Use this connect to use a 60% discount.