DMD 1.017 release

Walter Bright newshound1 at digitalmars.com
Mon Jul 2 10:56:35 PDT 2007


Deewiant wrote:
> I have a lot of code which looks like:
> 
> foo = foo.max; // sentinel value
> 
> maybeChangeFoo(foo);
> 
> if (foo == foo.init) // did foo change?
> 
> Now I have to duplicate the sentinel value in the code, which can be very
> annoying, and bug-prone if I forget to change one of the two. I can't always use
> the same value: usually it'll be 0, foo.min, or foo.max. It depends on what
> maybeChangeFoo can change foo to.

I understand, I had some code that did that too. The issue is I expect a 
steadily increasing use of generic code, and the inconsistency is going 
to cause future problems.

> Regarding consistency, .init isn't a static property. If you have:
> 
> struct S {
> 	int foo;
> }
> 
> S s = ...;
> assert (s.foo == S.foo); // oops, an error since S doesn't have foo
> 
> So there's already precedent for s.x not equaling typeof(s).x. If you really
> want s.init to not be context-dependent, make it invalid. It's very confusing
> for it to equal typeof(s).init.
> 



More information about the Digitalmars-d-announce mailing list