Asserts and side effects

2009-11-30 Thread Lars T. Kyllingstad
The following is a quote from a comment in the Reddit post about asserts that Walter just linked to: "Asserts are not without pitfalls, though. If you aren't careful, what to put in the asserts, the program could behave differently" A trivial example of this is: int i; write(i

Re: Asserts and side effects

2009-11-30 Thread bearophile
Lars T. Kyllingstad: > Would it be possible (and desirable) for the D compiler to statically > check that asserts have no side effects? Only pure asserts? If you put: assert (++i == 1); Inside a function precondition, it gets removed in release mode. Bye, bearophile

Re: Asserts and side effects

2009-11-30 Thread Denis Koroskin
On Mon, 30 Nov 2009 13:52:48 +0300, Lars T. Kyllingstad wrote: The following is a quote from a comment in the Reddit post about asserts that Walter just linked to: "Asserts are not without pitfalls, though. If you aren't careful, what to put in the asserts, the program could beh

Re: Asserts and side effects

2009-11-30 Thread KennyTM~
On Nov 30, 09 19:15, Denis Koroskin wrote: On Mon, 30 Nov 2009 13:52:48 +0300, Lars T. Kyllingstad wrote: The following is a quote from a comment in the Reddit post about asserts that Walter just linked to: "Asserts are not without pitfalls, though. If you aren't careful, what to put in the a

Re: Asserts and side effects

2009-11-30 Thread Denis Koroskin
On Mon, 30 Nov 2009 15:46:45 +0300, KennyTM~ wrote: On Nov 30, 09 19:15, Denis Koroskin wrote: On Mon, 30 Nov 2009 13:52:48 +0300, Lars T. Kyllingstad wrote: The following is a quote from a comment in the Reddit post about asserts that Walter just linked to: "Asserts are not without pitfal

Re: Asserts and side effects

2009-11-30 Thread Don
Denis Koroskin wrote: On Mon, 30 Nov 2009 15:46:45 +0300, KennyTM~ wrote: On Nov 30, 09 19:15, Denis Koroskin wrote: On Mon, 30 Nov 2009 13:52:48 +0300, Lars T. Kyllingstad wrote: The following is a quote from a comment in the Reddit post about asserts that Walter just linked to: "Asserts

Re: Asserts and side effects

2009-12-01 Thread Lars T. Kyllingstad
bearophile wrote: Lars T. Kyllingstad: Would it be possible (and desirable) for the D compiler to statically check that asserts have no side effects? Only pure asserts? Like Denis said, pure is a bit too strict. One just wants to make sure that the assert doesn't *change* any variables. It