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
-
Depending on the language it is useful. What if x is a truelike value like 1, "hello", {} in JS. But you need a boolean value to work with.
-
coolq48267yPersonally I don't mind this style of coding.
In python, I go crazy with syntactic sugar 😀 -
@novopl ah, yes I thought it said x? true:false;
And I know you can use !!x for that but people may get confused by it. -
@Embeddeded but it could be a string or something else as well and y=(x != 0) doesnt make it more clear.
-
@Codex404 So, a type that could be "Null" or "None"?
1.:
isValid = someObject ? true : false;
2.:
isValid = someObject != null
3.:
isValid = someObject != null ? true : false
4.:
isValid = !!someObject
I'd still vote for 2!
A piece of my soul dies when I see code like this:
Y = x ? false : true
I was already mad because the file that contained this line was written in a way that makes it really hard to fix any bugs or add feature that were supposed to be already implemented, then the sight of this just made me feel sad
undefined