3 ms·
Another possible solution is to require initialization of reference types upon declaration, instead of silently supplying a new default object if no initializat
by _delirium 16y ago
Another possible solution is to require initialization of reference types upon declaration, instead of silently supplying a new default object if no initialization is given. A bit more verbose, but might be clearer (esp. in Java-land, where stuff happening behind the scenes without explicit code is frowned on).
Ocaml basically does that, though it feels sort of second-nature rather than a restriction, because syntactically, the only way to get a reference is to take a reference of something. Eiffel "attached types" are similar (guaranteed to always be "attached" to a non-Void value), but have a somewhat more complex scheme of possibilities: http://docs.eiffel.com/sites/docs.eiffel.com/files/void-safe-eiffel.pdf http://docs.eiffel.com/sites/docs.eiffel.com/files/void-safe...
A big potential problem, I think, would be whether people use null-setting patterns often enough that they would work around the proposed change, by using these default-constructed objects as glorified null values, maybe by having them set an "I'm a dummy object" flag internally or something.