Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

What's terrible about truthy and falsy? How do you even have a language without a definition of what is truthy and what is falsy?


There are several languages that only allow booleans in such comparisons.

There you can't do e.g. a bare:

  if (a)
for things that e.g. in C/Java etc would be "truphy" (like 0, null, etc). Instead you need to do:

  if (a != null) 
(that is, check with an expression that returns an actual boolean true or false, not anything truthy/falsy that "coerces" to true/false).

In the same way, where in Python you'd do:

  a = ""
  if not a:
     print "this will be printed"
there you'd do it like:

  if not (a == "") -- or if not a.isEmpty():
    ...
or some such.


Sure, but then "truthy" for that language is just true, and "falsy" is just false. It's still relevant to understand the concept of "what is considered true, and what is considered false", even if the answer is simple for certain langauges.


>Sure, but then "truthy" for that language is just true, and "falsy" is just false.

Sure, but this stretches the meaning of "truphy" and "falsy", which was invented to describe the extra coercions to true/false.

A language only allowing explicit true and false just has a concept of true and false, not of truthy and falsy.


> this stretches the meaning of "truphy" and "falsy", which was invented to describe the extra coercions to true/false

Do you have a citation for this? I’m looking for a source which doesn’t consider true to be truthy, or false to be falsy, and I’m not finding one.


Truthy is "what is considered true in a conditional". It’s still a meaningful question, with a meaningful answer, even in languages where the only thing truthy is the value true.


If "what is considered true in a conditional" is literally only `true` then a language has no "truthy" values.

I mean, you're free to interpret it how you want but nobody else would agree with your definition.


Well, the people who read or write for this site would agree: https://developer.mozilla.org/en-US/docs/Glossary/Truthy. So not nobody.


> What's terrible about truthy and falsy?

Basically it's very error prone. It's difficult to remember the rules which are usually quite complicated which leads to mistakes.

Much better just to be explicit.

> How do you even have a language without a definition of what is truthy and what is falsy?

You make it so that `if` only works on `bool` types, and don't implicitly convert other types to `bool`. For example if you want to check if string is non-empty, then you have to do `if (the_string != "") {` rather than `if (the_string) {`, which may cause your code to unexpectedly fail if e.g. the string is "false".




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: