Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
@calmyourtities Whenever you read a comment posted to you, do you always start off going "calm your titties? Why is this person telling me to calm my titties what the fuck?" Before realizing it's just your name? I feel liked I'd do that...
-
@ThatDude I'm adopting you as my new best friend. You have no say in the matter.
Also! With my first account I was talking about ducks so much because of that post I had up, that my phone started auto correcting fuck to duck again... (And j swear a LOT so this was particularly astounding) -
@Torbuntu now correct me if I'm wrong.. because I often am... But I'm pretty sure that would never compile lmfao
-
@IDontGiveADuck people feel obligated to tell me to calm my tities (and sometimes have the nerve to tell me that tities is spelled "tittles") because they think its funny. no one has yet realized its supposed to be ironic.
-
@ThatTallNerd I just assumed he was talking about some obscure esoteric language that I don't know about or something... Like Fetlang
-
It is better if you literally have a variable named x,a better variable name would be fine for if (checkTrue)
-
@Matthewb but even if it is x, unless you're using something like python, you know that x is a Boolean anyway and with that kind of crap naming convention putting it either way won't make it more or less readable :P
-
@ThatTallNerd so far in my experience javascript and in languages where you can set a boolean to null
-
Ares4TW627y@ParkCity The alphabet is more like a spectrum anyway. Who says it has to identify as another letter? Maybe deep down x is an emoji.
-
D--M22667yIf the majority of the code base does == true, then follow whats been previously done, no reason to change semantics.
One arguement is that from a glance or during a code review and your on github or something in a meeting room it may be easier to read for some.
I think what would help you a lot is if you sat down with your coworker and made a style guideline. -
daveq4377yIf you name your variables properly it shouldn't matter. Yeah
if(x)
Doesn't read well but don't name your variables as x or other unclear things. Name then something like 'canDoSomething'. Then it reads
if(canDoSomething)
And that makes much more sense. If the variable is a bool it's perfectly valid and reads more naturally -
I usually stick to (x == true) for the sake of readability. I also ensure braces after if and for even if it's only one line.
-
jsmrcaga7807y@IDontGiveADuck if you're writing JavaScript
if(x) means, if x has a value and the value is not null or 0
where as
if(x === true) (notice the 3 ===) means if x is strictly equal to true, and not only truthy...
But again... it's js.
Don't hate reply ^^ -
@daveq you can't do it in most languages UNLESS it's a bool :) so if it's like that then it's a bool...
Also I just used x as an example... If you didn't catch that and actually think I name my variables x I mean... :S -
@exceptionalGuy if (x) is no less readable though... Or if (isDefault) to be more specific...
Also, everyone should ensure braces even if it's one line... Just because you CAN skip the braces, doesn't mean you should... -
You are correct and I can prove it.
In C you can accidentally assign inside of if expressions if you forget the extra equal sign
If(x = 1)
Therefore prefer the
If(x) so you can avoid an entire class of bugs 🙄
Alternatively switch order
If(1 == x)
I'd ban x == 1 stlye personally if I was writing guidelines and force either inversion or removal of equals -
@IDontGiveADuck but reading explicit code i can see what its doing calms the beast inside me to kill the programmer before me who wrote it. I personally dont know about python but in every other language if i saw "if (x)" and couldnt tell shat it was doing or for id go to jail for premeditated murder. X could be not null and that statement would be true but id have no idea what x actually was or was for
-
@Matthewb If it's written that way then there's no way it can be anything but a non-nullable Boolean... Otherwise it wouldn't compile (unless you're using Python)
-
wxcazee9097yActually in JavaScript this makes sense! Because Object or "1" can be truthy. But JavaScript is not a real language anyway.
-
@andros705
that is probably because c has no boolean
so there is nor really an alternative other than really weird stuff involving negation and comparing to 0
like if(!x == 0)
Related Rants
My coworker insists that:
if (x == true)
Is better than:
if (x)
I'm losing my mind.
Send Help.
rant
no
just no
please help