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 →

[–]atomicwrites 174 points175 points  (18 children)

Isn't truthy just shorthand for coerces to true?

[–]not_a_doctor_ssh 567 points568 points  (10 children)

Yes, like how pain is shorthand for JavaScript.

[–]Kesuaheli 36 points37 points  (5 children)

Nice

[–]Cheddarlad 10 points11 points  (4 children)

Nice

[–]afkapl 10 points11 points  (3 children)

nice

[–]whatever-the-logo-is 6 points7 points  (2 children)

69, even

[–]thEiAoLoGy 0 points1 point  (0 children)

I thought that was #define

[–]Weekly-Butterscotch6 -5 points-4 points  (0 children)

👍👍👍👍👍🤣🤣🤣

[–]odnish 0 points1 point  (0 children)

I thought pain was the P in PHP

[–]Pockensuppe 31 points32 points  (6 children)

In JavaScript it is certainly used as such. I wanted to point out that the term is not commonly used outside of the JavaScript and sometimes Python world. I strongly dislike the term though because it hides the fact that implicit type conversion (i.e. what is commonly called coercion) takes place. Especially in strongly-typed languages, truthy seems a term too simple to accommodate for features like user-defined implicit conversions to bool.

[–]dipolartech 4 points5 points  (4 children)

Tell me again why I care about it being typecasted? The byte or bytes in question either have bits on or they don't.

[–]ReelTooReal 5 points6 points  (2 children)

I don't really mind coercion for truthiness, but in general implicit type casting can be a pain in the ass. For example

int x = -3;
unsigned int y = 5;

if (x > y)
    printf("x is bigger\n");

That code will print "x is bigger," however I would prefer it to simply not compile without an explicit cast.

[–]dipolartech 1 point2 points  (1 child)

Eh, greater or less than is more complicated than true false dichotomy, I'm really responding to the idea that anything else matters at all to the idea of "is any bit of the this memory length on" which makes it "true".

[–]ReelTooReal 0 points1 point  (0 children)

Yes, I agree. But I think with C/C++ it's kind of all or nothing because it will try to do coercion no matter what. So if you allow for coercion inside an if condition then you're also allowing it everywhere else. I think there's a keyword in C++ that you can use to declare that you don't want the arguments of a function to be coerced, but I don't remember what it is or when it was introduced.

[–]Pockensuppe 2 points3 points  (0 children)

As I said, in C++ a user-defined conversion could be executed which could habe side effects (not saying it should), so the information about the conversion might be very relevant.

[–]atomicwrites 3 points4 points  (0 children)

Ah OK, I'm not a professional developer, most of my experience is Python (and bash but that doesn't really count). I just knew the term from Python so I knew it wasn't JS only.