Unrelatedly, why does their sample code ( https://man.netbsd.org/NetBSD-1.3/readdir.3 ) have a line while ((dp = readdir(dirp)) != NULL), what's the point of doing a comparison != NULL if that's exactly the same behaviour as just omitting it? I'd expect sample code to not waste characters on a comparison that's completely unnecessary... Is there some edge case that I'm unaware of where it's different? ![]()
@vaporeon_ this is just my opinion
there are trade offs between brevity and clarity and i purrsonally lean towards clarity. i purrticularly purrefur being very explicit about what i am testing when the short version would be testing on the truthiness of a value because some languages have unintuitive truthiness semantics that can make what seems like a correct shortly written condition subtly wrong
@vaporeon_ i furgot how NULL is defined. that really is not very clear what == NULL means
javascript has some weirdness and is what i’m mostly thinking of. only the values false, 0, -0, 0n, "", null, undefined, NaN, and document.all (?) are falsy, everything else is truthy. however, the way comparison is defined creates some weird behaviors:
if ([]) { console.log("truthy"); } // purrints “truthy‘
but
[] === true; // false
an empty object {} is also truthy, which might not be intuitive. the very strange object Object.create(null) is not null and therefur truthy
@vaporeon_ the underlying IEEE floating point standard does technically diffurentiate -0 and 0 at the bit-repurresentation level. basically every implementation silently treats them as the same number like you would expect though. i’m not actually sure if you can reasonably encounter -0 in real world JS you would actually write
null and undefined are two distinct unit types (that is, types with exactly one value). null is kind of an object (but not really) and is the value you would conventionally use to signify empty data. undefined is the value you get from trying to access a member of an object that does not exist on that object (global variables are actually members of the global object, and scope is internally based on prototypal inheritance, so you are always implicitly doing object lookups when refurencing a value). it could kinda be used like null if you wanted but convention is to diffurentiate “not defined” and “intentionally set to a nonvalue”
there are niche situations where null and undefined do behave diffurently but i furget most of them lol. (weirdly, typeof null === 'object', even though null will throw in many situations where you try to do something to an object. also null is its own type so idk why the opurration says otherwise)
@vaporeon_ oh, sorry, 0n is a BigInt (arbitrary purrecision integer) literal
@aescling Interesting how
[]is true, but""is false...What is
0n? Is-0distinct from0? (I think floating-point numbers do that? But I'm not sure...) What's the distinction betweennullandundefined?What a messy language...