Common ground. Re: Null references redux

Jeremie Pelletier jeremiep at gmail.com
Tue Sep 29 07:51:02 PDT 2009


bearophile wrote:
> Don:
> 
>> Maybe if D had better flow analysis, the demand for 
>> non-nullable references wouldn't be so great.
> 
> I know a good enough C# programmer that agrees with you, he says that thanks to the flow analysis C#compiler performs, the need for non-nullable references is not so strong.

Which is what I said half a dozen times in this thread :)
Disclaimer: I have only read about C#, didn't code it.

>> (Neither is a pure subset of the other, flow analysis works for all 
>> variables, non-nullable references catches more complex logic errors. 
>> But there is a very significant overlap).
> 
> I like how you can see things a little more clearly than other people (like me).
> Flow analysis helps for all variables, but it's limited in the scope. Nonnullable references are a program-wide contract, their effect extends to called functions, etc. And helps avoid null tests inside them too.
> Probably flow analysis is the most important among such two features. I think having both is better, they can work in synergy.
> 
> Bye,
> bearophile

Flow analysis must be implemented by the compiler, nonnull references 
can be enforced by a runtime wrapper (much like smart_ptr enforces 
addref and release calls in C++, you don't see smart_ptr being moved in 
the language spec even if half the C++ community would drool over the idea).

The best thing about flow analysis is that we can take away the whole 
default initializer idea, since it was made to make non-initialized 
variable errors easy to pinpoint in the first place, not as a 
convenience to turn "int a = 0;" into "int a;".

Besides DMD must have some basic flow analysis already since it does 
notice when a code path does not return, it just need to be extended to 
include unitialized variables.



More information about the Digitalmars-d mailing list