News for hackers. Stuff that matters.
Re:I open sourced my game along with a tutorial on how to ma... by TedDoesntTalk on Monday July 06, 2020 @12:46AM (#23744781)
How about this: The empty string and 0 are truthy. Why?
Re:I open sourced my game along with a tutorial on how to ma... by DarkWiiPlayer on Monday July 06, 2020 @03:36AM (#23745574)
0? Because Lua isn't C. It makes sense for C to treat 0 as falsey, because (void*)0 is Cs way of expressing a nil-value, as well as not having a dedicated boolean value to keep the language simpler.

Lua, both has a dedicated nil value and a boolean type, so there's no reason whatsoever to treat zero as falsey, other than the C cargocult.

As for empty strings, I really don't see the rationale behind it. An empty string is not nothing. At the very least, it still holds the length-data of 0, so it's conceptually more than just nil and should thus still be truthy.

Re:I open sourced my game along with a tutorial on how to ma... by cl3misch on Monday July 06, 2020 @01:39AM (#23745036)
Maybe because all variables are `nil` by default, and checking on undeclared variables does not raise an error. So `if foo then ... end` is often used as an existence check, where `foo = 0` should be truthy.
Re:I open sourced my game along with a tutorial on how to ma... by pansa2 on Monday July 06, 2020 @03:43AM (#23745606)
If you make the empty string falsy, surely you need to make all empty collections falsy?

Python does this, which leads to people checking whether a list is empty using `if l` rather than `if len(l) > 0`. I‘d rather they stuck with “explicit is better than implicit”.

Re:I open sourced my game along with a tutorial on how to ma... by anonymoushn on Monday July 06, 2020 @02:50AM (#23745345)
This is probably a good thing, if you don't want to have tickets filed about whether midnight (time of day) is truthy, whether Jan 1, 1970 is truthy, why some type of empty collection is truthy but others are not, etc.
Re:I open sourced my game along with a tutorial on how to ma... by pansa2 on Monday July 06, 2020 @03:38AM (#23745582)
> This is probably a good thing, if you don't want to have tickets filed about whether midnight (time of day) is truthy

Agreed. Here is an example of exactly that in Python:

https://bugs.python.org/issue13936