www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - invariant()

reply Michel Fortin <michel.fortin michelf.com> writes:
In D1 you had to write:

	invariant
	{
		...
	}

while in D2, to disabiguate with invariant being overloaded with 
immutability you had to write:

	invariant()
	{
		...
	}

Now that the use of the invariant keyword in D2 has returned to its 
single original meaning of class invariant, is there still a reason for 
it to require an empty parenthesis? Should I fill a bug?

-- 
Michel Fortin
michel.fortin michelf.com
http://michelf.com/
Apr 12 2009
next sibling parent davidl <davidl nospam.org> writes:
在 Sun, 12 Apr 2009 20:57:28 +0800,Michel Fortin  
<michel.fortin michelf.com> 写道:

 In D1 you had to write:

 	invariant
 	{
 		...
 	}

 while in D2, to disabiguate with invariant being overloaded with  
 immutability you had to write:

 	invariant()
 	{
 		...
 	}

 Now that the use of the invariant keyword in D2 has returned to its  
 single original meaning of class invariant, is there still a reason for  
 it to require an empty parenthesis? Should I fill a bug?

It will be good if it will be the same in both D1 and D2 -- 使用 Opera 革命性的电子邮件客户程序: http://www.opera.com/mail/
Apr 12 2009
prev sibling next sibling parent reply Jarrett Billingsley <jarrett.billingsley gmail.com> writes:
On Sun, Apr 12, 2009 at 8:57 AM, Michel Fortin
<michel.fortin michelf.com> wrote:
 In D1 you had to write:

 =A0 =A0 =A0 =A0invariant
 =A0 =A0 =A0 =A0{
 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0...
 =A0 =A0 =A0 =A0}

 while in D2, to disabiguate with invariant being overloaded with
 immutability you had to write:

 =A0 =A0 =A0 =A0invariant()
 =A0 =A0 =A0 =A0{
 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0...
 =A0 =A0 =A0 =A0}

Actually, the D1 compiler now accepts the "invariant() {}" syntax, so if you want your code to work with both D1 and D2, use that. Whether it'll be going away, I'm not sure. I guess Walter is the only one who knows that.
Apr 12 2009
next sibling parent Michel Fortin <michel.fortin michelf.com> writes:
On 2009-04-12 10:29:52 -0400, Jarrett Billingsley 
<jarrett.billingsley gmail.com> said:

 Actually, the D1 compiler now accepts the "invariant() {}" syntax, so
 if you want your code to work with both D1 and D2, use that.

Actually, I was just converting some D1 code to D2 (with no intention of keeping it D1-compatible) and had to change a few of them, which made me wonder whether Walter has considered reversing this change to D2 now that the reason for doing it has disappered. -- Michel Fortin michel.fortin michelf.com http://michelf.com/
Apr 12 2009
prev sibling parent Walter Bright <newshound1 digitalmars.com> writes:
Jarrett Billingsley wrote:
 Whether it'll be going away, I'm not sure.  I guess Walter is the only
 one who knows that.

I see no point to breaking invariant() again.
Apr 12 2009
prev sibling next sibling parent reply Stewart Gordon <smjg_1998 yahoo.com> writes:
Michel Fortin wrote:
<snip>
 Now that the use of the invariant keyword in D2 has returned to its 
 single original meaning of class invariant,

Where do you get that idea from??? Stewart.
Apr 12 2009
parent reply Michel Fortin <michel.fortin michelf.com> writes:
On 2009-04-12 19:08:08 -0400, Stewart Gordon <smjg_1998 yahoo.com> said:

 Michel Fortin wrote:
 <snip>
 Now that the use of the invariant keyword in D2 has returned to its 
 single original meaning of class invariant,

Where do you get that idea from???

D 2.020's changelog: - immutable now is implemented. I though this meant that invariant was replaced by immutable as a type modifier. Apparently, it was not: invariant can still be used as a synonym to immutable. This also makes: (invariant int).stringof == "immutable(int)" So I guess I should change my initial question: is this use of invariant going to be kept indefinitely? -- Michel Fortin michel.fortin michelf.com http://michelf.com/
Apr 12 2009
parent Stewart Gordon <smjg_1998 yahoo.com> writes:
Michel Fortin wrote:
<snip>
 D 2.020's changelog:
 
 - immutable now is implemented.
 
 
 I though this meant that invariant was replaced by immutable as a type 
 modifier.

My first reaction was to look for documentation on what the keyword means and have no success. And so I filed this.... http://d.puremagic.com/issues/show_bug.cgi?id=2572
 Apparently, it was not: invariant can still be used as a 
 synonym to immutable.

If it meant that invariant had been removed, then that's what it would've said. Stewart.
Apr 13 2009
prev sibling parent "Kristian Kilpi" <kjkilpi gmail.com> writes:
On Sun, 12 Apr 2009 22:00:43 +0300, Walter Bright  
<newshound1 digitalmars.com> wrote:
 Jarrett Billingsley wrote:
 Whether it'll be going away, I'm not sure.  I guess Walter is the only
 one who knows that.

I see no point to breaking invariant() again.

Will 'invariant' as a type modifier go away? If so, then of course the parentheses could be dropped out from the class invariant. Or, both the syntaxes ('invariant {}' and 'invariant() {}') could be supported (imho, only one syntax would be better though). Currently the syntaxes of the class invariants and unit tests are a bit inconsistent, and I don't like it too much. :)
Apr 13 2009