5
lxmcf
8y

Not sure if other programming languages class a Boolean as an integer value buuuuuuut...

The amount of times I've seen people do code such as...

if(value == true) {
variable = "blah blah";
} else if(value == false) {
variable = "blah";
}

Instead of doing a simple 1D array and going...

variable = strings[value];

It drives me crazy, such a small thing that has no real benefit but... Ugh... Whyyyyyyy

Comments
  • 0
    variable is either an array of size 0 or 1. This still doesn't assign the "blah" or "blah blah" into variable and makes the code far less readable. Even if the assignment was done you would have to traverse the array to figure out which index had the thing. I'm not sure I get your point?
  • 6
    Ternary operator to the rescue!

    variable = value ? "blah blah" : "blah";

    PS: both variants are poor quality, but the first is easier to understand than an array created extra for this.
    PPS: incredibly poorly chosen variable names.
  • 0
    Yes! @Huuugo, good use if the language supports it.
Add Comment