Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
antinazi7633dNo null is not undefined, they are different thing. Think of it more like symbols or jungian archetypes. They actually have deep spiritual meaning to me.
Meditate for an hour and maybe you will get it. -
antinazi7633dFor real in practice they are just false. Just test for !!variable and everything is casted to boolean, problem solved.
-
Demolishun3496333d@antinazi Yeah, I ended up doing falsy test to catch both null and undefined.
Here, enjoy this programming dad joke:
How come every time I get a vtable error I always look it up and think I need a destructor, but in reality I remember that it is because I made a class with a Q_OBJECT macro in a cpp file? Why does Qt moc me so...? -
Ranchonyx1065533dFor this specific bullshit I made myself a class with a static method as follows:
Guard.AgainstNullish<T>(val: T): asserts val is Exclude<val, undefined | null>
Or at least something like that.
This actually is properly typed so that if you use an IDE which does the whole typescript shebang, it'll ensure that below the Guard.AgainstNullish(); call, the passed parameter is never null or undefined.
Do not use plain JavaScript, it's a kick in the balls ready to happen. -
Demolishun3496333d@Ranchonyx It is used as a scripting tool for QML. Not sure I could even get Typescript to work with it.
-
kiki3533533dSeriously though, semantically speaking, I use undefined as “untouched nothing” and null as “deliberate nothing”. If something in my code is null, it means I set it. If it’s undefined it means it was the default.
-
Demolishun3496333d@kiki in my code I was deliberately seeing to null on variable definition. But a later assignment was putting in undefined. No idea which call it was yet (another thing to figure out). So checking for falsely was more appropriate in this case. The logic is kinda messy and probably needs redone.
-
antinazi7633dNull is the substance of what is not. But it is still something, whereas undefined is something that is defined as a paradox, because it exists but at the same time it does not. Null is undefined, but undefined is not null, and vice-versa.
I think about it a lot at night while I masturbate. -
kiki3533533d@Demolishun yes, I use falsy and truthy conditions in JS. I don’t care if it’s undefined or null, I only care that it’s falsy
-
CoreFusionX343032dFalsy is kind of dangerous since zero or empty strings trigger it.
You can just coercing compare against either null or undefined to catch both and not have falsy positives, as in...
null == undefined //true
null === undefined //false -
CoreFusionX343032dAlso, on a more architectural matter, the whole null vs undefined really comes from the C implementation.
Null is null in that sense, like, a symbol that exists, but has no value.
(JS also historically had trouble with the fact that NULL was 0.)
Undefined is a byproduct of interpreted languages. In a compiled language, it makes no sense because it won't even compile, but when you execute line by line, especially as REPL, you are bound to encounter the situation of someone using a symbol that's not defined. Hence undefined.
The comparison rules, I agree are weird, but probably the lesser evil in trying to not break existing code.
Undefined is also, as a clutch, used as a semantical "void". -
ars1407532dUndefined is what would result if something quite literally does not exist as a property. For example if you json parse a string and the property was not there at all you would get undefined.
Null is something that exists but has “no value” set to it yet. The problem is that you can technically declare something and set it to undefined anyway. Or null. And both can be used in the same way because you normally only check for falsy.
I can see why you may want to distinguish between not set and non existent. But I hate it.
I can’t wait to switch jobs next month so I can leave this language behind.
Speaking of JS gotchas. Why is there a null and undefined? I guess undefined doesn't exist, but null is it exists, but is null? Had a bug related to this. I was checking for null, but undefined was getting in there even though I defined the variable as null beforehand. All I can guess is some assignment shoved undefined in there. But that just doesn't make sense to me. So an existing variable can be undefined as well? lol
I am glad this is not my primary language for heavy lifting. Fuck this noise.
I was going to do this as a rant. But it turned into an ironic joke. I am adding an old meme, but it checks out for accuracy.
joke/meme
justshit
javascript