Passing a boolean to a function instead of creating two functions-Collection of common programming errors
I would say this is a BIG no-no due to the following reasons :
Readability : There is only a very minor difference between the two keywords setVisible()
and setInvisible()
and its easy to mis-read while scrolling through 100s of lines of code.
Semantics : Having 2 distinct setXXX() and setYYY() functions implies that there exist 2 different properties. While you will know that both of the map to the same internally, this may NOT be obvious to someone new to your library/API.
Logic : In addition to the set functions, you would be implementing the corresponding getVisible()
and getInvisible()
for good measure as well. With code snippets like the following sure to cause enough confusion.
setVisible()
...
getInvisible()
(wait, what??)
setInVisible()
...
getVisible()
(whats the state now??)