The evil of null


So, I get all sorts of errors and bugs - when I try to simulate, whatever it is supposed to simulate, it goes in an endless loop of “trying to simulate / encountering error / not pausing to show error, lol”, my wins in “multiplayer” are never recorded, etc.

But the most frustrating this has to be the power of null.
This site’s compilator flips out whenever it so much as sees null. It’s like it’s the anti to its code, the most diabolical evil, the most sinister sinister. No, it doesn’t crash, the code does not return an error - the holier-than-thou compiler simply points its regal nose up high and in disgust says “E-e-e-e-e-e-e-ew! There is a null value here! Icky!” and does not allow the execution to go past that point.

I’m using JavaScript and lo and behold - there shouldn’t be any such problems. Their existence is seriously annoying, not to mention they are cramping my style. I don’t know if this site is aimed only at beginners, but even then such actions would be completely wrong.

To clarify - the compiler starts screaming “null” without actually evaluating the expression in which the null is (stupid, I know).


The code doesn’t hate Null, it hates being told to do something WITH null.
Check your if statements. Null values are a great way to introduce issues in compiled code. So in the interest of best practice, we shouldn’t leave un-checked nulls.

I never have issues as long as I craft if statements to check for null. (In fact I intentionally use nulls) if (x) blah;

But we must be careful about what we do within that if.
If you have multiple targeted events within the if

if (enemy) {

There is no guarantee that the target is still alive/still exists for that second command.

Which is why I tend to prefer while (enemy && >0) { if (enemy) attack; if (enemy) bash) } or the like, ensuring my target exists and is alive. More work for the compiler, but fewer failures, and less left to assumption.


That seems highly unlikely. Please report such issues appropriately—accompanied by a SSCCE / MCVE, so we can actually verify that such a bug exists and be able to fix it.

Nice! I I couldn’t have said it better myself. :smiley: