Null references redux
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Sat Sep 26 16:38:56 PDT 2009
Walter Bright wrote:
> grauzone wrote:
>> Walter Bright wrote:
>>> grauzone wrote:
>>>> Not so useful.
>>>
>>> It's *still* far more useful than generating corrupt output and
>>> pretending all is ok.
>>
>> But nobody argues in favor of that?
>
> It's implicit in the argument that some default should be used instead.
> That's what I'm trying to point out.
>
> Even forcing an explicit initializer doesn't actually solve the problem
> - my experience with such features is programmers simply insert any old
> value to get the code to pass the compiler, even programmers who know
> it's a bad idea do it anyway.
I think you're starting to be wrong at the point where you don't realize
that many bugs come from references that people have forgotten to
initialize. Once you acknowledge those, you will start to realize that a
reference that must compulsively be initialized is valuable.
You think from another perspective: you strongly believe that *most* of
the time you can't or shouldn't initialize a reference. Your code in
Phobos reflects that perspective. In the RegExp class, for example, you
very often define a variable at the top of a long function and
initialize it halfway through it. I trivially replaced such code with
the correct code that defines symbols just where they're needed.
Andrei
More information about the Digitalmars-d
mailing list