Fixing C's Biggest Mistake

norm norm.rowtree at gamil.com
Sat Dec 31 23:35:17 UTC 2022


On Saturday, 31 December 2022 at 01:45:06 UTC, Walter Bright 
wrote:
>
> ... Leaving a null entry is faster, and if you forget to add a 
> check, the hardware will check it for you.
>

This won't be deemed acceptable by most devs I know outside the 
small batch utility space.

Trapping a seg-fault does not work, you lose context and cannot 
gracefully continue operating. A NULL object existing at runtime 
is not a fatal error and should be recoverable. Dereferencing a 
NULL pointer and triggering a seg-fault, even with a handler in 
place, is a fatal error and unrecoverable.

Is it really the performance hit of checking for NULL? Well C++ 
it then and only pay for what you use. If devs don't want the 
runtime cost of a SW null check in their code, then they don't 
use the Nullable type. Call that type whatever you want, in 
Python it is Optional. But having the compiler statically enforce 
a null check is incredibly useful in my experience because more 
times than not you do not want to crash.

On that note, mypy statically checks for a None check prior to 
accessing any Optional type. I bring this up as well because 
Python is inherently unsafe and typing is not high on the Python 
dev radar, but even Python devs consider this a useful feature.

bye,
norm


More information about the Digitalmars-d mailing list