| Thread overview | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
|
April 12, 2009 invariant() | ||||
|---|---|---|---|---|
| ||||
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/
| ||||
April 12, 2009 Re: invariant() | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Michel Fortin | 在 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/ | |||
April 12, 2009 Re: invariant() | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Michel Fortin | On Sun, Apr 12, 2009 at 8:57 AM, Michel Fortin <michel.fortin@michelf.com> wrote:
> In D1 you had to write:
>
> invariant
> {
> ...
> }
>
> while in D2, to disabiguate with invariant being overloaded with immutability you had to write:
>
> invariant()
> {
> ...
> }
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.
| |||
April 12, 2009 Re: invariant() | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Jarrett Billingsley | 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/ | |||
April 12, 2009 Re: invariant() | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Jarrett Billingsley | 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.
| |||
April 12, 2009 Re: invariant() | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Michel Fortin | 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.
| |||
April 13, 2009 Re: invariant() | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Stewart Gordon | 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/ | |||
April 13, 2009 Re: invariant() | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | 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. :)
| |||
April 13, 2009 Re: invariant() | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Michel Fortin | 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. <snip> If it meant that invariant had been removed, then that's what it would've said. Stewart. | |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply