On 2012-08-19 05:54:49 +0000, Walter Bright <[email protected]> said:
On 8/18/2012 9:21 PM, Nick Sabalausky wrote:
After actually *using* both D (default-initialization) and C#
(statically/conservatively ensure things can't be accessed without
being explicitly inited), and I'm convinced the benefits of the static
checks easily outweigh the fear of a knee-jerk "=0".
I'm less willing to throw default initialization out - I like it & rely
on it. The C# approach pretty much ends default initialization,
including for user defined types.
I like default initialization too, and I rely on it. By that I mean
that all the time I write "size_t count;" and assume it'll be default
initialized to zero. I like it because it's less typing and it's
simple: if I don't assign anything it's zero. I can't do that for
floats or chars, because the default initialization gives me a unusable
value. In my mind C#-style conservative flow analysis errors are better
than default initialization to a bogus value because they catch the
problem at compile time. But on the other side I'd rather not give up
on integer default initialization to zero, as I actually prefer this
over everything else.
So Walter, which default initialization do you like an rely on?
As I said, personally, I'd have everything initialized to zero by
default. But at this point you can't really change this even if you
want to: some program somewhere might rely on float being initialized
to NaN by default and might start to give erroneous results if you
change the default. (Notice the irony?)
--
Michel Fortin
[email protected]
http://michelf.ca/