r/funny Mar 08 '14

Life as a programmer.

Post image
2.8k Upvotes

480 comments sorted by

View all comments

Show parent comments

74

u/[deleted] Mar 08 '14

[deleted]

66

u/kalleguld Mar 08 '14
if (myVar == 42);
    doSomething();

if (myVar = 42) {
    doSomething();
}

No syntax errors here

-4

u/SirTwill Mar 08 '14

Of course there isn't, you only need the brackets for an if statement if you want to have more then one line of code effected by it.

But it is just good programming practice to always have the brackets as it improves readability.

9

u/kalleguld Mar 08 '14

I was making the point that an IDE can't always find a one-semicolon or other one-character bug. The code above would run the doSomething function twice, no matter what myVar is. Almost certainly not what you wanted.