Re: Let's not make invariants const

2012-08-06 Thread Alex Rønne Petersen
On 05-08-2012 11:47, Simen Kjaeraas wrote: On Sun, 05 Aug 2012 11:36:56 +0200, Jakob Ovrum wrote: On Friday, 3 August 2012 at 19:19:24 UTC, Alex Rønne Petersen wrote: Does anyone else find this behavior too strict? Yes. Sounds like yet another case of forcing bitwise const on something that

Re: Let's not make invariants const

2012-08-06 Thread Alex Rønne Petersen
On 06-08-2012 19:57, deadalnix wrote: Le 05/08/2012 11:47, Simen Kjaeraas a écrit : On Sun, 05 Aug 2012 11:36:56 +0200, Jakob Ovrum wrote: On Friday, 3 August 2012 at 19:19:24 UTC, Alex Rønne Petersen wrote: Does anyone else find this behavior too strict? Yes. Sounds like yet another case

Re: Let's not make invariants const

2012-08-06 Thread deadalnix
Le 05/08/2012 11:47, Simen Kjaeraas a écrit : On Sun, 05 Aug 2012 11:36:56 +0200, Jakob Ovrum wrote: On Friday, 3 August 2012 at 19:19:24 UTC, Alex Rønne Petersen wrote: Does anyone else find this behavior too strict? Yes. Sounds like yet another case of forcing bitwise const on something t

Re: Let's not make invariants const

2012-08-05 Thread Simen Kjaeraas
On Sun, 05 Aug 2012 11:36:56 +0200, Jakob Ovrum wrote: On Friday, 3 August 2012 at 19:19:24 UTC, Alex Rønne Petersen wrote: Does anyone else find this behavior too strict? Yes. Sounds like yet another case of forcing bitwise const on something that should only be logically const. Pleas

Re: Let's not make invariants const

2012-08-05 Thread Jakob Ovrum
On Friday, 3 August 2012 at 19:19:24 UTC, Alex Rønne Petersen wrote: Does anyone else find this behavior too strict? Yes. Sounds like yet another case of forcing bitwise const on something that should only be logically const. Please stop forcing bitwise constancy on everything. Not everythi

Re: Let's not make invariants const

2012-08-05 Thread Simen Kjaeraas
On Sat, 04 Aug 2012 16:08:42 +0200, Andrei Alexandrescu wrote: I think a stance could be taken either way. Const invariants are like the European police; non-const invariants are like US police. Funny, my impression of the US/European police is the exact opposite. -- Simen

Re: Let's not make invariants const

2012-08-04 Thread Davidson Corry
On 8/3/2012 1:48 PM, Alex Rønne Petersen wrote: The problem here is that making invariants const *now* means that using them in conjunction with Phobos code becomes next to impossible. Casting away const will become common practice, and that ain't exactly the way we want to go. :/ Understood an

Re: Let's not make invariants const

2012-08-04 Thread Andrei Alexandrescu
On 8/4/12 4:45 AM, Jonathan M Davis wrote: D needs to work well with const, but one of the goals is also to make it so that it's not required if you don't want to or can't use it. Forcing invariants to be const goes against this. But that decision was probably made before the recent decisions on

Re: Let's not make invariants const

2012-08-04 Thread Christophe Travert
"Era Scarecrow" , dans le message (digitalmars.D:174206), a écrit : > I would think it does however during verbose output specifying > if an invariant or contract is changing data and that may alter > behavior. Signatures in some place should be by default const, pure, nothrow. This is the ca

Re: Let's not make invariants const

2012-08-04 Thread Jonathan M Davis
On Saturday, August 04, 2012 10:37:55 deadalnix wrote: > I don't. > > Actually, it save from many mistakes. You are always free to cast away > const. This is unsafe, but you are in an invariant and aren't supposed > to do non const operation. At the end, this is fair. All that would be required t

Re: Let's not make invariants const

2012-08-04 Thread deadalnix
Le 03/08/2012 22:41, Alex Rønne Petersen a écrit : Further, I had to insert casts that cast away constness in some cases because the standard library just isn't const-friendly enough. We need to get our priorities straight. Why don't you think this is actually the issue ? (I do). BTW, const i

Re: Let's not make invariants const

2012-08-04 Thread deadalnix
Le 03/08/2012 21:19, Alex Rønne Petersen a écrit : Hi, This: $ cat test.d class A { int i; invariant() { i = 42; } } Currently doesn't compile: $ dmd test.d test.d(7): Error: can only initialize const member i inside constructor (Obviously this example is silly, but it's just meant to illus

Re: Let's not make invariants const

2012-08-04 Thread Era Scarecrow
On Saturday, 4 August 2012 at 07:15:50 UTC, Jonathan M Davis wrote: The problem is that if the this pointer/reference is const, then you can't call any member functions which aren't const, and you can't call any non-const functions on any member variables, because _they're_ const, because the t

Re: Let's not make invariants const

2012-08-04 Thread Jonathan M Davis
On Saturday, August 04, 2012 09:06:19 Era Scarecrow wrote: > As mentioned before, doesn't 'const' _only_ apply to the current > (this) object and not anything else? Besides the contracts can't > have lasting side effects that would change logical execution. > How would changing the current object

Re: Let's not make invariants const

2012-08-04 Thread Era Scarecrow
On Saturday, 4 August 2012 at 06:53:16 UTC, Mehrdad wrote: It's worth pointing out the obvious, I.e. that as long as 'const' is physical const instead of logical const (which is always), invariants and contracts can't be const, because that would restrict them from calling methods that are logi

Re: Let's not make invariants const

2012-08-03 Thread Mehrdad
It's worth pointing out the obvious, i.e. that as long as 'const' is physical const instead of logical const (which is always), invariants and contracts can't be const, because that would restrict them from calling methods that are logically but not physically const. So I think they probably

Re: Let's not make invariants const

2012-08-03 Thread Jonathan M Davis
On Friday, August 03, 2012 12:36:41 H. S. Teoh wrote: > IMO, if you need to be changing stuff inside invariants, then you're > using it wrong. Invariants are intended to verify program logic, not to > do things like altering object state. The point is to be able to compile > with invariant code tur

Re: Let's not make invariants const

2012-08-03 Thread Marco Leise
Am Fri, 03 Aug 2012 22:40:02 +0200 schrieb "bearophile" : > Another solution (that doesn't replace the need for the > prestate!) is ghost fields, that are class instance/struct fields > usable only inside contracts and that vanish in release mode: > http://d.puremagic.com/issues/show_bug.cgi?id=

Re: Let's not make invariants const

2012-08-03 Thread Era Scarecrow
On Friday, 3 August 2012 at 20:48:29 UTC, Alex Rønne Petersen wrote: The problem here is that making invariants const *now* means that using them in conjunction with Phobos code becomes next to impossible. Casting away const will become common practice, and that ain't exactly the way we want to

Re: Let's not make invariants const

2012-08-03 Thread Alex Rønne Petersen
On 03-08-2012 22:32, Davidson Corry wrote: On 8/3/2012 1:14 PM, Paulo Pinto wrote: Personally I feel D's contracts are still a bit off of what Eiffel, .NET and Ada 2012 offer. On 8/3/2012 1:01 PM, Alex Rønne Petersen wrote: So what if, for whatever reason, the invariant needs to track and

Re: Let's not make invariants const

2012-08-03 Thread Alex Rønne Petersen
On 03-08-2012 22:40, bearophile wrote: Alex Rønne Petersen: So what if, for whatever reason, the invariant needs to track and maintain some state in order to catch some kind of ugly bug? This is legitimate practical need. I know two or more ways to solve that problem, one of them is to implem

Re: Let's not make invariants const

2012-08-03 Thread Alex Rønne Petersen
On 03-08-2012 22:17, Davidson Corry wrote: On 8/3/2012 12:40 PM, bearophile wrote: H. S. Teoh: IMO, if you need to be changing stuff inside invariants, then you're using it wrong. Invariants are intended to verify program logic, not to do things like altering object state. The point is to be a

Re: Let's not make invariants const

2012-08-03 Thread bearophile
Alex Rønne Petersen: So what if, for whatever reason, the invariant needs to track and maintain some state in order to catch some kind of ugly bug? This is legitimate practical need. I know two or more ways to solve that problem, one of them is to implement the prestate (old). That's probabl

Re: Let's not make invariants const

2012-08-03 Thread Davidson Corry
On 8/3/2012 1:14 PM, Paulo Pinto wrote: Personally I feel D's contracts are still a bit off of what Eiffel, .NET and Ada 2012 offer. On 8/3/2012 1:01 PM, Alex Rønne Petersen wrote: So what if, for whatever reason, the invariant needs to track and maintain some state in order to catch some ki

Re: Let's not make invariants const

2012-08-03 Thread Davidson Corry
On 8/3/2012 12:40 PM, bearophile wrote: H. S. Teoh: IMO, if you need to be changing stuff inside invariants, then you're using it wrong. Invariants are intended to verify program logic, not to do things like altering object state. The point is to be able to compile with invariant code turned of

Re: Let's not make invariants const

2012-08-03 Thread Paulo Pinto
On Friday, 3 August 2012 at 19:43:18 UTC, Simen Kjaeraas wrote: On Fri, 03 Aug 2012 21:36:41 +0200, H. S. Teoh wrote: IMO, if you need to be changing stuff inside invariants, then you're using it wrong. Invariants are intended to verify program logic, not to do things like altering object st

Re: Let's not make invariants const

2012-08-03 Thread Alex Rønne Petersen
On 03-08-2012 21:36, H. S. Teoh wrote: On Fri, Aug 03, 2012 at 09:19:22PM +0200, Alex Rønne Petersen wrote: [...] class A { int i; invariant() { i = 42; } } Currently doesn't compile: $ dmd test.d test.d(7): Error: can only initialize const member i inside constru

Re: Let's not make invariants const

2012-08-03 Thread bearophile
H. S. Teoh: IMO, if you need to be changing stuff inside invariants, then you're using it wrong. Invariants are intended to verify program logic, not to do things like altering object state. The point is to be able to compile with invariant code turned off, and still have the program work exa

Re: Let's not make invariants const

2012-08-03 Thread Simen Kjaeraas
On Fri, 03 Aug 2012 21:36:41 +0200, H. S. Teoh wrote: IMO, if you need to be changing stuff inside invariants, then you're using it wrong. Invariants are intended to verify program logic, not to do things like altering object state. The point is to be able to compile with invariant code turne

Re: Let's not make invariants const

2012-08-03 Thread Alex Rønne Petersen
On 03-08-2012 21:19, Alex Rønne Petersen wrote: Hi, This: $ cat test.d class A { int i; invariant() { i = 42; } } Currently doesn't compile: $ dmd test.d test.d(7): Error: can only initialize const member i inside constructor (Obviously this example is silly, bu

Re: Let's not make invariants const

2012-08-03 Thread H. S. Teoh
On Fri, Aug 03, 2012 at 09:19:22PM +0200, Alex Rønne Petersen wrote: [...] > class A > { > int i; > > invariant() > { > i = 42; > } > } > > Currently doesn't compile: > > $ dmd test.d > test.d(7): Error: can only initialize const member i inside constructor [...] > I beli

Re: Let's not make invariants const

2012-08-03 Thread Simen Kjaeraas
On Fri, 03 Aug 2012 21:19:22 +0200, Alex Rønne Petersen wrote: Hi, This: $ cat test.d class A { int i; invariant() { i = 42; } } Currently doesn't compile: $ dmd test.d test.d(7): Error: can only initialize const member i inside constructor (Obviously this e

Let's not make invariants const

2012-08-03 Thread Alex Rønne Petersen
Hi, This: $ cat test.d class A { int i; invariant() { i = 42; } } Currently doesn't compile: $ dmd test.d test.d(7): Error: can only initialize const member i inside constructor (Obviously this example is silly, but it's just meant to illustrate the point of this thr