From: Paul Brannan Date: 2003-02-20T02:06:33+09:00 Subject: Re: How to test for existence of instance variable? On Thu, Feb 20, 2003 at 01:11:37AM +0900, ahoward wrote: > i disagree with this, i would never do this in C > > struct > { > int x; > } > s; > > bzero (&s, sizeof (s)); > > s.x = 0; /* redundant! */ This isn't what I intended to mean. The bzero call is unnecessary, since x is properly initialized on the following line. What would be a problem is this: struct { int x; } s; printf("%d\n", s.x); because you are using a value that may not be initialized (if s has static storage duration, then x will be initialized to 0, but it's not necessarily a good idea to depend on this behavior). > just as i would never in ruby do > > class S > attr_accessor :x > > def initialize > @x = nil # redundant > end > end > > s = S.new > > since ruby does this for me and it simply clutters the source file IMHO. I see no clutter here. It is clear here that @x is being initialized to nil, whereas if you leave out the initialization of @x, then it is not immediately obvious that you intended for @x to have the value nil. Paul