4 ms·
Last thing, and this is an alt account because of my procrastination settings, go ahead and type this into your browser's inspector Console: ``` const foo = {
by __gabe_ 4y ago
Last thing, and this is an alt account because of my procrastination settings, go ahead and type this into your browser's inspector Console:
```
const foo = {};
const bar = foo.baz + foo.something;
console.log(bar);
```
What is bar at the end of this? It's NaN. There's no error thrown at all. What does this mean? If you have some complicated math going on somewhere and all of a sudden you use undefined objects because something went wrong, now all your calculations are incorrect. Hmmm, this sounds familiar. Oh yes! It's just like when you read garbage data in C++ because of out of bounds memory. What does this commonly lead to...? Oh yes! It commonly leads to your app seemingly behaving erratically because it's using garbage data now, and it's pretty much untraceable!
In other words, if you had actually programmed in either of these languages for more than a couple months, you probably would have run into problems like this in both languages. What conclusion does that lead a sane person to? It leads them to the conclusion that segfaults (which are caused by writing to an unallocated page and often go undetected and just put garbage data somewhere in your program) can be just as difficult to debug as JavaScript undefined objects (which can happily be used in most calculations in JavaScript without throwing any errors).
Here are a few examples of programmers that are upset because they can't trace the source of their bug in the apparently completely traceable language of JavaScript:
https://stackoverflow.com/questions/2631464/whats-with-the-random-javascript-errors https://stackoverflow.com/questions/2631464/whats-with-the-r...
https://joa.medium.com/hunting-a-javascript-heisenbug-cb13cef9f012 https://joa.medium.com/hunting-a-javascript-heisenbug-cb13ce...
https://stackoverflow.com/questions/26563329/detecting-when-any-variable-in-a-large-js-program-is-set-to-nan https://stackoverflow.com/questions/26563329/detecting-when-...
https://levelup.gitconnected.com/dont-fall-into-the-nan-trap-d2fbc5536e50 https://levelup.gitconnected.com/dont-fall-into-the-nan-trap...
https://arcade.ly/blog/2020/02/23/how-to-debug-nan-and-nan-propagation-bugs-in-javascript/ https://arcade.ly/blog/2020/02/23/how-to-debug-nan-and-nan-p...
- deltaonefour 4y agoNo. Because in C++ no segfault may be thrown at all. You can put a for loop around an out of bounds memory write and it may hit a segfault at index 300 for no apparent reason or the segfault likely even happens AFTER the for loop. The examples you posted are typical complaints. Those errors don't hold a candle to out of bounds memory errors though. Typical solutions in the examples you posted involved people suggesting breakpoints for really complex datapaths. The solution to the problem is straightforward however tedious. One of the bugs you posted involved a bug in the interpreter. If that's the case all bets are off.