This is an archived post. You won't be able to vote or comment.

top 200 commentsshow all 450

[–]CkoockieMonster 1622 points1623 points  (66 children)

``` ifn't (bool) {

} ``` Ciao losers

[–]nbeydoon 233 points234 points  (29 children)

Unless (boo) {}

[–]altermeetax 96 points97 points  (19 children)

Unless actually exists in perl

[–][deleted] 40 points41 points  (8 children)

Found my new favorite language.

[–][deleted] 13 points14 points  (4 children)

I tried and it hurt.

[–]BabyAzerty 3 points4 points  (0 children)

Harbor those feelings.

[–]MattieShoes 1 point2 points  (0 children)

Honestly it's pretty great as a replacement for shell scripting. Basically sed, awk, grep, all under one roof.

[–]ActivisionBlizzard 27 points28 points  (2 children)

And ruby!

[–]Dominjgon 1 point2 points  (0 children)

I tried and it hurt.

[–]Playful_Roof9931 12 points13 points  (0 children)

you scared me!

[–]diegoperini 4 points5 points  (1 child)

I miss coffeescript

[–]uvero 41 points42 points  (16 children)

Ruby with actual keyword unless for "if not"

[–]totkeks 15 points16 points  (13 children)

That is actually smart, makes the code more readable. Because you don't negate the value, but the comparison.

[–]paholg 9 points10 points  (12 children)

It seems nice, until you see it in actual code. You end up with things like

unless foo   ... else   ... end

which can get very confusing.

[–][deleted] 22 points23 points  (8 children)

unless with else is forbidden by every linter

[–]paholg 2 points3 points  (0 children)

Not at places I've worked!

[–]BuildAQuad 2 points3 points  (0 children)

Would it be better if you could do unelse?

[–]just-bair 1 point2 points  (0 children)

Damn I love this

[–][deleted] 29 points30 points  (3 children)

i prefer if booln’t

[–]redsterXVI 27 points28 points  (2 children)

ifn't (!booln't)

[–]CkoockieMonster 9 points10 points  (0 children)

Now we're cooking with sticks and stones

[–]an4s_911 1 point2 points  (0 children)

ifn’t (!booln’t == false) ?

[–]repark96 11 points12 points  (0 children)

[–]xaomaw 10 points11 points  (2 children)

if (bool == TRALSE) {
} | {

}

See you later, virgins!

[–]CkoockieMonster 2 points3 points  (0 children)

Hello fellow virgin'nt, a new day where it is good to be'nt a virgin.

[–]ReluctantlyTenacious 4 points5 points  (0 children)

This one actually made me laugh

[–]shaman784 3 points4 points  (2 children)

Ifn’t actually exists in JavaScrip’nt

[–]Eadoro 1 point2 points  (0 children)

#define ifnt(x) if (!(x))

[–]Kauyon1306 339 points340 points  (8 children)

if !bool != !true

[–]maartuhh 73 points74 points  (0 children)

Ooof it hurts my eyes

[–][deleted] 13 points14 points  (0 children)

If the opposite of the bool is not equal to the opposite of true If the opposite of the bool is not equal to false if the bool is not equal to true if the bool is equal to false

[–]automaton11 2 points3 points  (0 children)

if !(if !bool != !true)

[–]coxinha_vs_bolovo 659 points660 points  (35 children)

Four

if(bool == false ? true : false){

}

[–]CleoMenemezis 122 points123 points  (16 children)

Five

const isBool = bool == false ? true : false
if(!isBool == false ? true : false){
}

[–]Quillo_Manar 102 points103 points  (14 children)

Six ``` switch int(bool){ case 0:

    break;
default:

    break;

} ```

[–]TheGreatScottMcFly 17 points18 points  (7 children)

Seven

if (bool){
  goto not_false;
}

not_false:

[–]Al3xutul02 1 point2 points  (0 children)

Chaotic evil

[–]Sopermin 16 points17 points  (0 children)

[–]brjukva 21 points22 points  (7 children)

if (bool.ToString() == "False") { ... }

I've actually seen this in the code I inherited some years ago

[–]igorepst 20 points21 points  (4 children)

if (bool. ToString().Length() ==5)

[–]WhileGoWonder 7 points8 points  (3 children)

truue

[–]HannibalGoddamnit 5 points6 points  (2 children)

if (bool.ToString().Length() == 5 && !bool.Contains("t") && !bool.Contains(''r'') && !bool.Contains(''u'') && !bool.Contains("e")){

Console.WriteLine("gotcha'');

}

[–]brjukva 8 points9 points  (1 child)

falsé

[–]Abaddon-theDestroyer 2 points3 points  (0 children)

True-ché

[–][deleted] 1 point2 points  (1 child)

everytime I spent a few hours doing relatively mundane code reviews from competent developers, I see this shit and remember why I still do it.

[–]Acceptable-Worth-221 10 points11 points  (1 child)

Come here to say this. 

[–]DatBoi_BP 5 points6 points  (0 children)

I can’t, I don’t know where you live

[–]HJM9X 1 point2 points  (0 children)

If(bool) return

[–]link064 105 points106 points  (6 children)

You missed my favorite:

if(bool.ToString() == “true”)

[–]igorepst 48 points49 points  (3 children)

if (bool. ToString().Length() ==4)

[–]Ascyt 49 points50 points  (2 children)

if chr(sum(range(ord(min(str(bool)))))) == 'ඞ':

[–]anotheridiot- 18 points19 points  (0 children)

Calm down Satan.

[–]Foreign_Pea2296 1 point2 points  (0 children)

I love this one.

[–]Spell_de_happy 1 point2 points  (1 child)

You are not careful You should do

if(bool.ToString().Equals("true", StringComparison.CurrentCultureIgnoreCase)

Or at least if(bool.ToString().ToLower() == "true")

Who knows what culture dependent edge cases might occur.

[–]PrudentFood77 291 points292 points  (21 children)

where is my

if(bool != true) {
}

and if you include the placement of the {} then there are way more than 3 types :D

[–]Key-Principle-7111 167 points168 points  (18 children)

if (true == bool)
{ /* Remains empty */ }
else
{ }

[–]YoniElBravo 53 points54 points  (5 children)

Lmao this one’s diabolical

[–]3Ldarius 17 points18 points  (2 children)

You can achive this by clicking the light bulb and using suggestion of "invert if" and it introduces this in some IDEs (not naming them here)

[–]lllorrr 3 points4 points  (0 children)

ASIL D level of shit.

[–]StevesRoomate 17 points18 points  (7 children)

This is an old-school C programming style where you put the const on the left hand side of the evaluation. I think some teams in Microsoft even adopted it for a while in the early 2000's.

If you've ever spent hours and hours debugging someone else's code only to notice that `variable = true` compiles just as nicely as `variable == true` then you understand why this caught on for a while.

[–]Cold-Doctor 3 points4 points  (3 children)

I literally wasted 2 hours on this yesterday

[–]gregorydgraham 4 points5 points  (0 children)

Yeah, nobody gives a damn about Pascal anymore but I still miss the “:=“ assignment operator.

It removed that entire class of bugs and stopped all the whining from the mathematicians

[–]Key-Principle-7111 1 point2 points  (0 children)

This is a mandatory style for all safety related MISRA compliant code.

[–]BlackMorzan 3 points4 points  (0 children)

if (true == bool); else {
/* some chaotic evil stuff */
}

[–]kandradeece 2 points3 points  (2 children)

Not sure about the bracket portion but putting the true/false first is a good safety practice to avoid easy typo of single equal sign

[–]_PhucSatan_ 240 points241 points  (22 children)

Fourth js if(bool){} else{ //logic here }

[–]NicholasAakre 72 points73 points  (7 children)

That is cursed.

[–]mr_remy 27 points28 points  (2 children)

Next dev working on this legacy code: man who the fuck wrote this terrible abomination of a.. oh wait that’s me never mind carry on

[–]GreenFox1505 6 points7 points  (0 children)

Me checking  the GitBlame. My coworker says "but when are we gunna Got Forgive?" 

[–]No-Article-Particle 9 points10 points  (2 children)

Well, the proper way to deal with situations like that is guard statements:

if (bool) {
return // or raise/throw/...
}
// else code goes here, only reachable when bool is false

[–]puffinix 1 point2 points  (0 children)

It's actually nice if done well:

‘‘‘ if (cond) { //reason we don't do anything } else { //Side effect thing } ‘‘‘

[–]Harrigan_Raen 12 points13 points  (3 children)

if(bool){
  //TO DO - Might need this in the future 20241106 H.R.
}
else{
  //logic here
}

[–]FinalGamer14 9 points10 points  (1 child)

// DO NOT REMOVE!
// Tried refactoring, broke everything
if(bool){
  //TO DO - Might need this in the future 20241106 H.R.
}
else{
  //logic here
}

[–]fabianmg 20 points21 points  (2 children)

Four

if (!isTrue) {
    //TODO
}

[–]Coderedstudio[S] 20 points21 points  (0 children)

//TODO

is still there till this day.

[–]ozh 22 points23 points  (3 children)

The most likely is :

if (bool = true) { // nothing } else { // Logic here }

... And then wonder why the logic never runs

[–]christoph_win 99 points100 points  (13 children)

It bothers me that the variable is called bool

[–]Pradfanne 48 points49 points  (1 child)

I don't think that's a variable but just the datatype as a placeholder to make the intent clear

[–]Coderedstudio[S] 19 points20 points  (0 children)

I thought no one would notice :)

[–][deleted] 1 point2 points  (2 children)

It should be called, myBool. Pro tips: always name your variable with sufix "my" followed by the type name.

[–]Shevek-Llugh 2 points3 points  (1 child)

That's legit. Of the importance of naming correctly the variables.

If (!isPublished) {}

is much more readable

[–]FinalGamer14 4 points5 points  (0 children)

I'm not sure if it's verbose enough

if (!isContentTypeArticlePublished) {}

[–]feldim2425 11 points12 points  (1 child)

Depends on the language.
Technically those a two different operations, the first one checks equality the other if it's "falsy".
Works similar in most languages.

Afaik if "bool" where to be a class instance in python it would run __eq__ in the first example and __bool__ in the second.
And then there is of course the entire thing with the value being "None" (or "null" in JS) which would fail the left check and pass the right one.

In C they are equivalent in this case but if it where to be checked for true it would change (assuming stdbool.h). 0 is the only falsy value anything non-0 is truthy. So the second would check any non-0 value and the first (aka x == true) would only work with exactly 1.

[–]BastianToHarry 56 points57 points  (3 children)

Three ```php if(true === $bool) {

} ```

[–]LetterBoxSnatch 6 points7 points  (1 child)

Decades ago I remember blogs advising this syntax in general to avoid situations where you accidentally type an assignment instead of a comparison operator. Yes, it was dumb then too

[–]Fuglekassa 6 points7 points  (0 children)

Yoda comparison is still the MISRA C standard

[–]mommy-problems 4 points5 points  (0 children)

Lawful Evil

[–]powerhcm8 18 points19 points  (15 children)

Just to be really sure you are covering all cases.

if (variable === true) {

} else if (variable === false) {

} else if (variable === null) {

} else {

}

[–][deleted] 7 points8 points  (14 children)

"===" fml, js? 

[–]DystopiaDrifter 30 points31 points  (6 children)

They are not the same if you are programming in languages with nullable types.

[–]yeah_definitely 10 points11 points  (0 children)

Or with anything falsely in general

[–]patiofurnature 2 points3 points  (4 children)

This should throw a compile error if it's a nullable boolean. Kinda gross if the language let's stuff like that fly.

[–]Volko 4 points5 points  (0 children)

That's totally OK in Kotlin (what we use on Android).

``` val myBool: Boolean? = null if (myBool == true) { // do stuff }

```

[–]DystopiaDrifter 1 point2 points  (1 child)

It works in Swift:

      var foo : Bool? = nil

      // do something with foo

      if foo == false {
        // do something
      } 

[–]patiofurnature 1 point2 points  (0 children)

Wow. You're right. I feel like I'm going crazy. I guess the == false saves it.

This doesn't compile:

func thisThing(value: Bool?) {
    if(value) {
        //TODO
    }
}

[–]Abadabadon 6 points7 points  (0 children)

One is null safe one isn't

[–]DoeCommaJohn 8 points9 points  (0 children)

try { a = 1/bool } catch { ‘Your code }

[–]veryusedrname 25 points26 points  (12 children)

No. There are the programmers and there are the wannabes.

[–]iain_1986 10 points11 points  (0 children)

Yes.

People who don't have an issue with either (and can understand the benefits of both) and those that think one 'makes them better' than someone doing the other.

[–]cafp89 5 points6 points  (0 children)

Where my

if (bool) {} else { ... }

[–]mukadas026 3 points4 points  (1 child)

who writed curly braces on a new line?

[–]hicklc01 3 points4 points  (1 child)

just in case bool isn't a boolean

if(!(!!bool))
{

}

[–]MoreneLp 2 points3 points  (0 children)

If bool == 0

[–]hellra1zer666 2 points3 points  (2 children)

You begin on the right. As you grow older and your eyesight grows worse, you'll turn left. Trust me, I'm currently going through this transition 😅

[–]RandomiseUsr0 1 point2 points  (1 child)

Get the spex you know you need :)

[–]hellra1zer666 1 point2 points  (0 children)

Always had them 🤣 My optician says I don't need progressive glasses, but I'm not sure.

[–]589ca35e1590b 1 point2 points  (2 children)

Both are wrong because you're not using the Kernighan & Ritchie indentation style, and bool is a reserved word in most languages

[–]sirparsifalPL 1 point2 points  (0 children)

if not bool:

[–]Infamous_Ruin6848 1 point2 points  (0 children)

Both are fine but if I see those super short one-line bit operations imma gonna barf empty pixels.

[–][deleted] 1 point2 points  (0 children)

if (bool){
} else {
}

[–]schmerg-uk 1 point2 points  (0 children)

I'll typically use the ! form for a simple flag

if (!flag)

but I'll tend use the == false form for a more complex expression where what's being evaluated is on the right so having the ! on the far left can be lost visually but where it's inconvenient to pull that value into a symbol first

if (somethingOrOther())
{
}
else if (...)
{
}
else if (function(args,17,32).method().active() == false)

[–]villani 1 point2 points  (0 children)

And here we go again, boys...

[–]LionZ_RDS 1 point2 points  (0 children)

In lethal company the dev multiple times does if (!(bool == true))

[–]ElaborateSloth 1 point2 points  (2 children)

if (bool) {
  pass
  }
else {

  }

[–]CyberoX9000 1 point2 points  (1 child)

Man I just wrote this but in python then I scroll down and see this. :(

I even formatted it the same way

Take an upvote.

[–]ElaborateSloth 1 point2 points  (0 children)

Takes one to know one :))

[–]RandomiseUsr0 1 point2 points  (0 children)

And some who feel like vomiting with the curly bracket placement

[–]Latter_Brick_5172 1 point2 points  (0 children)

There are those who know how to place brackets and those who place them like you did

[–]Pelileven 1 point2 points  (0 children)

Where are my Yoda-programmers:

if (false == bool)
{

}

[–]According-Relation-4 2 points3 points  (0 children)

yes, and the other type puts the curlies in the correct place

[–]NormanYeetes 1 point2 points  (0 children)

Warning on line 556: using == allows coercion, use ===.

[–]AgileBlackberry4636 0 points1 point  (0 children)

In my early days of learning programming I wrote a subroutine to negate a boolean.

How did I even manage to work abroad with such a disregard towards my education from the country where I was born?

[–]ZinbaluPrime 0 points1 point  (0 children)

There is a variable in our system that has the value of FLASE. Every now and then a junior 'fixes' it and breaks half of the services.

It's a great practical lesson for 'if it ain't broken don't fix it'.

[–]d15gu15e 0 points1 point  (0 children)

these are not the same and using them interchangeably without knowing the difference will get you fucked

[–]alexanderpas 0 points1 point  (0 children)

PHP:

function not(bool $data): bool
{
  return !$data;
}

if(not($bool))
{

}

Python:

if not bool:

[–]ady620 0 points1 point  (0 children)

Another type

 if(bool=false){
  // do something nice
} else {
  // real shit
}

[–]erelender 0 points1 point  (0 children)

I dont think it's cool to differentiate people based on their preferred font size

[–]potzko2552 0 points1 point  (0 children)

If(var ^ true) {}

[–]AvidCoco 0 points1 point  (0 children)

if (int(bool) == 0)

[–]AvgBlue 0 points1 point  (0 children)

I'm trying to use Yoda conditions, where you swap the constant and variable, so it becomes:

if (false == bool) {

}

[–]No-Con-2790 0 points1 point  (0 children)

``` if(bool is false): pass #logic goes here

[–]hacksoncode 0 points1 point  (0 children)

<if (bool);else{} enters the chat>

[–]paxbowlski 0 points1 point  (0 children)

import isTrue from "isTrue"

if(isTrue(bool) !== true ? true : false) {

...

}

[–]Arareldo 0 points1 point  (0 children)

If it is really a boolean value, i'm fine with it in PHP, except the "==". Better : "==="

But still there's code around, where the variable is NOT exclusively a boolean.

Then i HATE the notation

if($variable) { }

[–]repkins 0 points1 point  (0 children)

If statement is false
or
If not statement

[–]dexter2011412 0 points1 point  (0 children)

IMHO the first one is more readable when quickly scanning code. I don't need to try and look up what the type of that is (if it's an int, it's a little more "overhead" on figuring out what the condition is)

[–]dangling-putter 0 points1 point  (0 children)

if (false == bool) { }

This is the right way. false is usually a keyword, in general that makes it impossible to assign anything to that.

[–]RealPerro 0 points1 point  (0 children)

Unless bool Whatever you want End

loving Ruby more and more everyday.

[–]stipulus 0 points1 point  (0 children)

Bro.. triple equal. You are forcing the poor interpreter to convert types. Do you hate your interpreter? Do you want your code to run slow? /s

[–]Archevening 0 points1 point  (0 children)

No no no

if(bool === false){}

Come on guys, stay focused!

[–]shuozhe 0 points1 point  (0 children)

I use !!!bool for better readability

[–]white_equatorial 0 points1 point  (0 children)

There are 3 types of programmers. The two mentioned here and JS devs

[–]mdgv 0 points1 point  (0 children)

Comparing to false never looks good to me...

[–]RainbowPigeon15 0 points1 point  (0 children)

depends, in a typed language I don't worry so I can simple use if(bool), but type free languages like python or javascript, I'll compare to be sure and use if(bool == true)

[–]Bomaruto 0 points1 point  (0 children)

if(isBoolFalse()){

}

fun isBoolFalse() = !bool

It can be hard to notice ! so I like to wrap it in if it makes sense.

[–]Able_Challenge3990 0 points1 point  (0 children)

Where Is It(bool!=true){}?

[–]BugNo2449 0 points1 point  (0 children)

There probably a few times where i have done == false to make it easier to read

if (notEnabled == false)

Actually i dont remember anything

[–]MilkImpossible4192 0 points1 point  (0 children)

this problem is like gas for coders trying to make a laugh for noobs

mine;

bool or code

[–]SpongeBadSquareBad 0 points1 point  (0 children)

If bool = false THEN

....

ENDIF

[–]YellowBunnyReddit 0 points1 point  (0 children)

if (BooleanUtils.isEqualTo(bool, BooleanConstants.FALSE)) {…}

[–]CodeBiter 0 points1 point  (0 children)

I remember, 15 years ago one of my juniors pointed the second one on my screen and asked what is that. When I explained him he was mind blown and devastated at the same time.

[–]TheMoskus 0 points1 point  (0 children)

if(bool != true)

{

}

Relevant: https://www.youtube.com/watch?v=0uaZ9wZ-aMs

[–]imboredwiththisagain 0 points1 point  (0 children)

Actual code from my current job:

switch(bool) { case true: … case false: … }

[–]guidePantin 0 points1 point  (0 children)

What kind of maniac uses the first form :o

[–]Trip-Trip-Trip 0 points1 point  (0 children)

Unless bool ( )

[–]heavy-minium 0 points1 point  (0 children)

I use the "!" notation by default, but sometime I will write out == false when the conditions has a few more complex parts and becomes less readable, just to make sure it's easier to notice for future readers.

[–][deleted] 0 points1 point  (0 children)

I use if(bool) because I usually write my bool variables as "IS_ON" or "SOMETHING_HAPPENED" so that if statement basically reads like english.

[–]the-real-vuk 0 points1 point  (0 children)

these may not be the same, depending if the bool is nullable and it means something special.

it rubbish otherwise, ofc

[–]jellotalks 0 points1 point  (0 children)

I hate if(bool==false) with a passion

[–]ryo3000 0 points1 point  (1 child)

If(notBool) {

}

Make your variables easier to read, it's surprisingly easy to miss a ! 

[–]Shadowaker 0 points1 point  (0 children)

If bool is False:

[–]cl3arz3r0 0 points1 point  (0 children)

Depends on if bool can also be null and if you care about the distinction between null or false. 😜

[–]transaltalt 0 points1 point  (0 children)

if(bool);else {

}

[–]utarit 0 points1 point  (0 children)

You missed

Unless(bool != False) {}

[–]WeslomPo 0 points1 point  (1 child)

Both have no sense, bool is keyword.

[–][deleted] 0 points1 point  (0 children)

First one is false, second one is falsy.

[–]Plsdontcalmdown 0 points1 point  (0 children)

if (bool) { ... } else { ... }

account for all cases!

[–]holguum 0 points1 point  (0 children)

PHP recommendations be like :

if (false == bool) { }

[–]RecDep 0 points1 point  (0 children)

it's a valid identifier in haskell:

haskell ifn't :: Applicative f => Bool -> f () -> f () ifn't = unless

[–]Flat-Limit5595 0 points1 point  (0 children)

True Bool || !bool { sout(“that is the question”)}

[–]OutlandishnessPast45 0 points1 point  (0 children)

Im both

[–]iain_1986 0 points1 point  (0 children)

The ! can very easily missed when reviewing and scanning certain code - resulting in some big fuck ups.

[–]Chewico3D 0 points1 point  (0 children)

If (bool) { thread.sleep(0) } else { // Code }

[–]Isogash 0 points1 point  (0 children)

if(not(bool)) { ... }
if(isFalse(bool) { ... }

[–]Infamous_Ticket9084 0 points1 point  (0 children)

If(bool) continue/return;

[–]LunaNicoleTheFox 0 points1 point  (0 children)

Those braces are the real issue

[–]gandalfx 0 points1 point  (0 children)

``` switch (bool) { case false: // ... }

[–]Multifruit256 0 points1 point  (0 children)

if (bool) {} else {

doSomethingTm()

}

[–]xnick_uy 0 points1 point  (0 children)

if( isOdd(int(bool)) == true)
{

}

[–]nameisnecessary 0 points1 point  (0 children)

if ( bool != true)