Page 1 of 1
Equality vs. Assignment
Posted: Thu Apr 16, 2015 2:52 pm
by dandymcgee
So I'm feeling pretty damn awful today (some sort of throat cough) and I made literally the most elementary programming mistake in existence:
I honestly can't remember the last time I wrote one equal sign instead of two.. it's been years. I'm pretty embarassed, but I blame it on my health.
So tell us, when's the last time you wrote '=' instead of '=='?
Re: Equality vs. Assignment
Posted: Thu Apr 16, 2015 4:04 pm
by bbguimaraes
Also,
-Wparentheses, although I believe none of the are new to you.
Re: Equality vs. Assignment
Posted: Thu Apr 16, 2015 4:48 pm
by dandymcgee
The funniest part is this isn't my code base and I was trying to conform to someone else's style. I would *never* write "if(x == false)" in my own code, I'd just use "if(!x)".
Re: Equality vs. Assignment
Posted: Sat Apr 18, 2015 5:00 pm
by superLED
One time I was sick, I actually wrote if(x != true)
It's been a while since I wrote only one =, but when it happens, it takes forever to find the mistake, because who the fuck would think they wrote only one =? xD Always the last place I look.
Re: Equality vs. Assignment
Posted: Sat Apr 18, 2015 9:07 pm
by zeroandnull
dandymcgee wrote:I would *never* write "if(x == false)" in my own code, I'd just use "if(!x)".
superLED wrote:One time I was sick, I actually wrote if(x != true)
At the end of the day it doesn't matter because your compiler will optimize away stuff like that.
Re: Equality vs. Assignment
Posted: Sat Apr 18, 2015 10:16 pm
by dandymcgee
zeroandnull wrote:dandymcgee wrote:I would *never* write "if(x == false)" in my own code, I'd just use "if(!x)".
superLED wrote:One time I was sick, I actually wrote if(x != true)
At the end of the day it doesn't matter because your compiler will optimize away stuff like that.
It does matter, because on makes it easier to make the assignment mistake. Also, I had just gotten done updating some vb code.. and in vb a single '=' is the correct syntax. Ugh, I hate vb.