Fixing C's Biggest Mistake
Walter Bright
newshound2 at digitalmars.com
Fri Dec 30 02:03:39 UTC 2022
On 12/29/2022 12:45 PM, Adam D Ruppe wrote:
> The alternative is the language could have prevent this state from being
> unanticipated at all, e.g. nullable vs not null types.
It can't really prevent it. What happens is people assign a value, any value,
just to get it to compile. I've seen it enough to not encourage that practice.
If there are no null pointers, what happens to designate a leaf node in a tree?
An equivalent "null" object is invented. Nothing is really gained.
Null pointers are an excellent debugging tool. When a seg fault happens, it
leads directly to the mistake with a backtrace. The "go directly to jail, do not
pass go, do not collect $200" nature of what happens is good. *Hiding* those
errors happens with non-null pointers.
Initialization with garbage is terrible. I've spent days trying to find the
source of those bugs.
Null pointer seg faults are as useful as array bounds overflow exceptions.
NaNs are another excellent tool. They enable, for example, dealing with a data
set that may have unknown values in it from bad sensors. Replacing that missing
data with "0.0" is a very bad idea.
More information about the Digitalmars-d
mailing list