DMD 1.017 release

Deewiant deewiant.doesnotlike.spam at gmail.com
Sun Jul 1 03:25:08 PDT 2007


Walter Bright wrote:
> I'm going to have to retreat from this. Andrei made an argument that if
> one had:
> 
>     struct S
>     {
>         static int foo;
>     }
> 
>     S s = ...;
>     assert(s.foo == S.foo);
> 
> then, analogously:
> 
>     T t = ...;
>     assert(t.init == T.init);
> 
> should hold as well. Consistency is a strong argument.

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.

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.

-- 
Remove ".doesnotlike.spam" from the mail address.



More information about the Digitalmars-d-announce mailing list