Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are bools are sometimes referred to as "flags"?

Tags:

flags

boolean

Why are bools sometimes referred to as "flags"? Is it just a metaphor or is there some historical reason behind it?

like image 598
Komm Avatar asked Sep 27 '15 16:09

Komm


People also ask

Why are Boolean variables used as flags?

Concept: Boolean Flags Boolean values are regularly used to help maintain the state of a given piece of code. It is common to describe boolean variables as “boolean flags” - these often are used to turn on and off different behaviors that might be useful.

Are flags a code smell?

Flags tend to be code smells that, like a lot of technical debt, start out small and innocuous but then grow over time. They add conditional complexity at the expense of simplicity and clarity.

What does flag mean in Java?

Flag variable is used as a signal in programming to let the program know that a certain condition has met. It usually acts as a boolean variable indicating a condition to be either true or false.

How do you make a Boolean flag?

You can create boolean flags in your code using the static API. A container class is required, and you define your flag inside the container class. In the following examples, a container class and a boolean flag are defined. The flag name, videoChat, is derived from the flag variable name.


1 Answers

Flags are an ancient way to convey information. A flag, if we ignore lowering it to half-mast, has only two states - raised or not raised. E.g., consider a white flag - raising it means surrendering. Not raising it, the default state, means that you are not surrendering.

A boolean variable, like a flag, only has two states - true and false.

like image 62
Mureinik Avatar answered Oct 05 '22 02:10

Mureinik