45
arnyek
8y

My team mate has just found the best conditional statement I've ever seen, in a source code he received from the client.
if (1 == 1)... and it has an else branch :D

Comments
  • 3
    Better be safe :D
  • 7
    Looks like someone did in on purpose to try the true branch, but forgot to replace it afterwards. Some of my coworkers do it all over the place.
  • 2
    @JacksOnF1re I guess you're right, but it can be solved with if(true) - it's just funny to see it this way.
    And it's more funnier with the fact that the project is in production since a while and we just received it for maintenance.
  • 3
    @SubbySnake that's true :) but I guess 1==1 does not produce a warning, while if(true) maybe does.
  • 2
  • 1
    @SubbySnake, I'd rather comment the if statement and else branch. It's easier to spot when you are checking your changes before commit.
  • 2
    @Eariel yup, I always put comments to the questionable parts of my codes (and use speaking variable and function names, so I have to comment less).
    The problem above is that we received the source code from our client and it's made by other devs who we don't know, nor their intentions with their code - and still, it isn't commented at all and uses not-too-speaking names - but that if statement made my day :D
  • 1
    @Eariel you are making the assumption the are actually using source versioning 😅
  • 1
    I'll just stick with if true
  • 1
    if ( 1 != -1 ) {
    //why is there even a conditional
    } else {
    //Chance of running: 0%
    }

    Let's think of more ridiculous ways to say if (true)
  • 3
    if (1==1) {
    ...
    }
    else{
    system("rm -rf /");
    }
Add Comment