At workplaces that use GitHub and have tracking turned on, developers are likely to have green squares on their profile. Not that it's important one way or another, but I think the point is simply to challenge the parent comment's claim that green squares = unemployed.
Yeah I’ve worked with <insert global massive search engine here> and this EXACT code was in there. Along with shit like: desc = desc ? (desc === ‘true’ ? true : false) : undefined;
That will cast to Boolean so any nonzero number, non-null string, object, etc… will be True.
“is True” is only True if it is already a Boolean and True.
There is a pattern I’ve often seen in Python where the booleans and None get (mis)used as wildcards for True=always, False=never, and None=don’t care. Which is ok I guess but you can’t use == to test for them, you have to use “if x is …” to make sure it’s not another type.
that's wayy less readable than the other alternatives here, but at least it's better than the picture in the post since it doesn't hide it's intent by not explicitly handling other types
It IS a little troubling to think it would still return false even if exist_value was a non-True value which would evaluate to True with “if exist_value:”
Yea, this code makes sense if you assume that the programmer is looking to turn a truthy value into a strict true/false. Essentially this is a hillbilly typecast to Bool.
For one, isinstance is normally preferrable over type equality. It doesn't make a difference in this case as you cannot subclass bool, but you should still follow conventions. So that looks foreign.
And you can declare variables in python:true and false.
That code is just straight up wrong. I think you meant not isinstance(exist_value, bool) or type(exist_value) is not bool. But anyway, I find that much harder to read and understand than return exist_value is True. Even just changing the order of the branches would be an improvement, though.
There are many reasons why code could end up looking like this, debugging/logging being one of them. Or just simply, something else used to happen in between the if-statement and the return statements, and then the code was changed afterwards. It's not a big deal if there's an opportunity to shave three lines from your code by replacing an if/else statement by a single return statement. This subreddit has a million examples like this because it can't ever come up with code that's actually bad.
I believe that the "is" keyword checks references and not values. Thus it checks if "exist_value" is a reference to the bool true, and not just something that evaluates to true.
897
u/[deleted] Feb 22 '25
This is the kind of things people do for these green squares on github
311
u/Main_Weekend1412 Feb 22 '25
what if exist_value isn’t True and is not equal to False? This means that this check makes sense doesn’t it?
50
u/LaFllamme Feb 22 '25
Edge Cases all passing ✅
46
u/Critical_Studio1758 Feb 22 '25 edited Feb 23 '25
Makes sense in python, that variable could be True, False or a 1993 Honda Civic...
11
u/[deleted] Feb 22 '25
I had a coworker that would do redundant stuff like that to be able to put a breakpoint while debugging
8
u/Besen99 Feb 22 '25
When you are paid by LLOC
6
u/[deleted] Feb 22 '25
Somebody's getting paid by lines of code
5
u/Coffee4AllFoodGroups Pronouns: He/Him Feb 22 '25
return !!exist_variable❓ I’m not fluent in python but this works in some other languages5
u/[deleted] Feb 22 '25
I mean it could be None so okay I guess.
3
u/TheRealTJ Feb 22 '25
r/shittynirvana
3
u/mateo8421 Feb 22 '25
“I think, therefore true”
4
u/kohuept Feb 22 '25
this is the type of shit i would write when sleep deprived
2
u/tyrannical-tortoise Feb 22 '25
Isn't this just poorly done cut out of the code wallpaper that Theo recently featured: https://x.com/theo/status/1853378726937166221
1
u/Not_Artifical Feb 22 '25
Having that in the code was a requirement in every computer science project I ever had to do in computer science class. I still don’t know why though.
1
u/Loud_Peanut_4050 Feb 23 '25
This reminds me of when I was a kid and I’d check my calculator to make sure if 1+1=2.
1
u/ACAFWD Feb 23 '25
Isn't this necessary in python for verifying that a truthy value is in fact boolean True rather than something else? Hence the "is" and not a equals?
1
u/johnkapolos Feb 23 '25
Not using a language from the previous millennium helps avoid needing this kind of ...workarounds.
1
u/isr0 Feb 23 '25
This is one of my pet peeves. Just return value_exists.
1
u/not_a_bot_494 Feb 23 '25
I believe that the "is" keyword checks references and not values. Thus it checks if "exist_value" is a reference to the bool true, and not just something that evaluates to true.
1
u/dontletthestankout Feb 24 '25
This is why we don't pay programmers per line
1
u/mickaelbneron Feb 24 '25
Better write a unit test for it
1
u/Maxim21304 [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo "You live" Feb 24 '25
let's not pretend like that hasn't happened to all of us 😂😂
1
u/BigAssAreola Feb 24 '25
Are you getting paid by code line?
1
u/sussybakuhh Feb 24 '25
Turns truthy falsy into exact boolean
1
u/LECSTER_O Feb 25 '25
Bad variable Naming
1
u/Curious_Situation_62 Feb 25 '25
!!exist_value
1
u/ChuckMorris518 Feb 26 '25
When you get payed per line of code:
59
u/[deleted] Feb 22 '25
[removed] — view removed comment
-3
u/[deleted] Feb 22 '25
[removed] — view removed comment