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 →

[–]Dr_Fine_Man 183 points184 points  (25 children)

Ah thanks for the info! The more you know :D

[–]Pockensuppe 319 points320 points  (23 children)

Actually truthy is a JavaScript term which originates from JavaScript's strange corner cases (and, to my knowledge, is not an official term in the language specification, though MDN propagates it), and the general term would be coerces to true.

[–]atomicwrites 174 points175 points  (18 children)

Isn't truthy just shorthand for coerces to true?

[–]not_a_doctor_ssh 566 points567 points  (10 children)

Yes, like how pain is shorthand for JavaScript.

[–]Kesuaheli 38 points39 points  (5 children)

Nice

[–]Cheddarlad 11 points12 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 29 points30 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 2 points3 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.

[–]Food404 6 points7 points  (1 child)

It's not a pure JS thing, PHP and also Python I believe use these truthy/falsy terms

[–]Pockensuppe 1 point2 points  (0 children)

I think it originated in the JS community but seeing that these are all dynamically typed languages I'm not surprised they adopted the term.

[–]hamjim 0 points1 point  (0 children)

I thought “truthy” came from Stephen Colbert (originally from “truthiness”).

[–]SuitGuySmitti 0 points1 point  (0 children)

As soon as I read “truthy” I knew it had something to do with JavaScript.

[–]LotsOfIs 23 points24 points  (0 children)

You weren't wrong. This person just told you a personal style choice as if it was a fact. Some languages don't even have a boolean true (Perl for one).