Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why should I pass Boolean as a parameter instead of "boolean"?

Tags:

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.

like image 694
Jaime Garcia Avatar asked Apr 26 '10 18:04

Jaime Garcia


People also ask

Why you shouldn't use booleans in rest APIS?

If not carefully considered, booleans can: Obstruct API Extensibility. Mask and obfuscate Domain Clarity. Hamper Code Readability and Maintainability.

What is the advantage of using the type boolean rather than strings false true or integers 0 1?

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.

What is the difference between a Boolean variable and a Boolean value?

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.


1 Answers

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.

like image 73
BlairHippo Avatar answered Sep 24 '22 15:09

BlairHippo