A co-worker asked me to change a signature from using a primitive "boolean" to using a classed "Boolean". He didn't offer a very good explanation why?
Have any of you heard of this and can any of you explain why it matters or doesn't matter?
Edit: He mentioned that it was good practice for public methods.
The use of the field is just a flag that tells me whether to call one flow or another depending on whether it's true or false.
If not carefully considered, booleans can: Obstruct API Extensibility. Mask and obfuscate Domain Clarity. Hamper Code Readability and Maintainability.
Self Check 5.37. What is the advantage of using the type boolean rather than strings "false"/"true" or integers 0/1? Answer: You are guaranteed that there are no other values. With strings or integers, you would need to check that no values such as "maybe" or –1 enter your calculations.
Boolean variables can either be True or False and are stored as 16-bit (2-byte) values. Boolean variables are displayed as either True or False. Like C, when other numeric data types are converted to Boolean values then a 0 becomes False and any other values become True.
Is it database-related? If you have a boolean value in a database, it can hold one of THREE values -- true, false, and null. The Boolean object would let you mimic that behavior.
Basically, it's a matter of whether you want to deal with "null" as a potential input value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With