The fact that safe language implementations have to think hard about how to handle null pointer exceptions safely should have been a warning sign that null pointers are a bad thing to have in a language. Sadly nearly always unheeded.
-
-
Replying to @pcwalton @RichFelker
Are NPEs harder to handle safely, compared to other exception types?
2 replies 0 retweets 0 likes -
Replying to @ridiculous_fish @RichFelker
Yes. When you dereference a pointer you have to make sure that something safe happens if that pointer is null. It’s not as simple as making sure that the zero page is unmapped and catching SIGSEGV because you might overshoot the page if it’s e.g. an array.
2 replies 0 retweets 4 likes -
Replying to @pcwalton @RichFelker
Isn’t it as simple as emitting a null check at the point of dereference? That’s how Optional works after all.
2 replies 0 retweets 1 like -
Replying to @ridiculous_fish @RichFelker
That’s a *big* performance cost though. Not only in the cost of the actual test-and-branch, but also in the optimizations you inhibit.
2 replies 0 retweets 1 like -
The difference between Option<T> and nullable pointers is that you typically only use Option<T> where you actually need it, and the programmer can hoist the null checks out and only do them once instead of repeatedly inside loops, etc.
1 reply 0 retweets 2 likes -
Replying to @pcwalton @ridiculous_fish
A decent compiler would automatically hoist them out of loops.
1 reply 0 retweets 0 likes
It’s surprisingly tricky in some cases, when the nullable pointer values are in memory instead of SSA values.
-
-
Replying to @pcwalton @ridiculous_fish
Yeah, this is why I've gotten used to preloading struct members needed in loops into local variables (in C). Without restrict, compiler must usually assume something in loop could clobber them.
0 replies 0 retweets 1 likeThanks. Twitter will use this to make your timeline better. UndoUndo
-
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.