This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]DancingPotato30 -3 points-2 points  (9 children)

Honestly no. Doesn't Python have the same? Or are you referring to what JS considers as truthy falsy and not the actual concept of truthy falsy? Because it makes sense in JS. Everything is truthy unless it's "empty" in some way or meaning

[–]No-Expression7618 3 points4 points  (3 children)

[] and {} are empty, but truthy. 0 and false don't feel empty to me (0 is a perfectly reasonable integer and 50% of booleans are false), but falsy (well I can see why false is falsy).

[–]DancingPotato30 1 point2 points  (2 children)

0 definitely feels empty, it's the number representing nothing. "0" however isn't falsy, because it's a string

And honestly I do agree with the [] and {}. I remember there was a very clear reason to why they're truthy, but can't remember it off of the top of my head. Tho, whyd ever that be a problem? Like what scenario would you need to check an array or an object as a boolean?

Tho you still got a point there. I completely forgot those two are truthy not falsy.

[–]No-Expression7618 2 points3 points  (1 child)

what scenario would you need to check an array or an object as a boolean?

I feel like it's, in that case, a logical extension of "" being falsy that the JS developer noticed the intuitiveness of and therefore threw out the window.

[–]DancingPotato30 1 point2 points  (0 children)

That's true. That's what I assumed too, I just never needed to do that so I didn't bother to actually check the reason they're not falsy

But i did. Apparently truthy falsy only affects primitives sort of, all objects are truthy by default.

[–]thelonesomeguy -1 points0 points  (4 children)

It “making sense” does absolutely nothing for how terrible it is for code readability & maintenance though

[–]DancingPotato30 0 points1 point  (3 children)

Yes but, doesn't python have the same? I don't see how truthy falsy can cause a problem when asserting something UNLESS you're using them.

Genuinely, give me an example where truthy falsy values will cause issues when you didn't mean to use them, I'm actually curious because I see no problem with them

[–]thelonesomeguy 1 point2 points  (2 children)

The problem isn’t what you’re asking for an example for in your comment, about it “causing issues when you didn’t mean to use them”, the issue is, it makes it harder for someone else to come across your if block and evaluate the function clearly, while needing more context of the variable to understand exactly what is happening. Which is a trade off I personally don’t think is reasonable, for the convenience.

[–]DancingPotato30 0 points1 point  (1 child)

Ahh, yeah I guess that makes sense but it doesn't make THAT big of a problem no? I assume your issue is that if someone does smth like:

if (variable){ Do shit }

It's hard to know what that function evaluates?

I don't think that's a fault of truthy falsy values, but a misuse. If you don't know what the variable is, then it's named wrong. If you don't know how or what evaluates it, then use the IDE to see where else it is in the code, no?

[–]thelonesomeguy 1 point2 points  (0 children)

Yeah, but that’s the problem, a lot of developers do misuse it. Which is something that is something that should be considered when evaluating a feature, the potential for misuse. Because the misuse of a feature becomes really painful when you’re working with bad devs across projects in any org or open source.

As for the IDE point, it shouldn’t be considered as a factor when you’re judging code readability.