Re: Contract programming syntax

2009-04-09 Thread Stewart Gordon
Tomasz Sowiński wrote: I like removing "body". But maybe we can make contracts a bit nicer by removing braces if the contract contains only one statement: void foo() in assert(something); out assert(something_else); { ... } would that be ambiguous to the compiler? Probably not, but I'm not

Re: Contract programming syntax

2009-04-09 Thread Jarrett Billingsley
On Thu, Apr 9, 2009 at 2:56 AM, Don wrote: > Jarrett Billingsley wrote: >> >> On Wed, Apr 8, 2009 at 10:59 PM, Christopher Wright >> wrote: >>> >>> Or just your style guide. But even if you can demonstrate significant >>> benefits (and I don't see any benefits, really), inertia is against you. >>

Re: Contract programming syntax

2009-04-09 Thread Kagamin
Stewart Gordon Wrote: > Finally, a counter-argument with which I agree. Moreover, having in/out > contracts as part of the function body suggests that they are part of > what is overridden. But the language doesn't quite work like that. I thought, they're overriden.

Re: Contract programming syntax

2009-04-09 Thread Tomasz Sowiński
Jarrett Billingsley Wrote: > OK, then what about: > > void foo() > in { ... } > out { ... } > { ... } > > the 'body' keyword is completely arbitrary. There is no ambiguity here. > > Also, I almost never use contracts because of their verbosity. It's > much shorter - and functionally equivalen

Re: Contract programming syntax

2009-04-09 Thread Stewart Gordon
Michel Fortin wrote: I believe the syntax should make the contracts part of the function signature, not part of the function body, because contracts are about expressing the function's interface. So I disagree with your proposed syntax which puts the contracts as part of the body. Finally,

Re: My body is ugly (was Re: Contract programming syntax)

2009-04-09 Thread Stewart Gordon
Danny Wilson wrote: 2 x Fifthed + 1 = Eleventhed! Don't you mean 2 × Fifthed + Firsted = Eleventhed ? Stewart.

Re: Contract programming syntax

2009-04-09 Thread Don
Jarrett Billingsley wrote: On Wed, Apr 8, 2009 at 10:59 PM, Christopher Wright wrote: Or just your style guide. But even if you can demonstrate significant benefits (and I don't see any benefits, really), inertia is against you. I don't think Walter would change it for anything but extreme prov

Re: Contract programming syntax

2009-04-08 Thread Jarrett Billingsley
On Wed, Apr 8, 2009 at 10:59 PM, Christopher Wright wrote: > > Or just your style guide. But even if you can demonstrate significant > benefits (and I don't see any benefits, really), inertia is against you. I > don't think Walter would change it for anything but extreme provocation. Are you sugg

Re: Contract programming syntax

2009-04-08 Thread Christopher Wright
Jarrett Billingsley wrote: On Wed, Apr 8, 2009 at 6:38 PM, Christopher Wright wrote: Then take this example: void foo(int i) { if (i < 0) return; in { assert (i != -1; } } This is confusing. There's a simple solution: define the function body grammar to only allow in{} and out{} blocks

Re: Contract programming syntax

2009-04-08 Thread Michel Fortin
On 2009-04-08 10:46:19 -0400, bearophile said: I like contract programming, it helps me avoid bugs. This is an example from the docs: long squareRoot(long x) in { assert(x >= 0); } out (result) { assert((result * result) <= x && (result+1) * (result+1) >= x);

Re: My body is ugly (was Re: Contract programming syntax)

2009-04-08 Thread Danny Wilson
2 x Fifthed + 1 = Eleventhed! Op Wed, 08 Apr 2009 20:51:17 +0200 schreef Alexander Pánek : Fifthed. How about using bigfloat for that?

Re: Contract programming syntax

2009-04-08 Thread Christopher Wright
Jarrett Billingsley wrote: On Wed, Apr 8, 2009 at 4:51 PM, Christopher Wright wrote: No. This proposed syntax change is quite misleading. Contracts cannot access the function's local variables, but it looks like they can. Contracts are executed at particular times, but that syntax makes them lo

Re: Contract programming syntax

2009-04-08 Thread Jarrett Billingsley
On Wed, Apr 8, 2009 at 6:38 PM, Christopher Wright wrote: > Then take this example: > > void foo(int i) > { >   if (i < 0) return; >   in { assert (i != -1; } > } > > This is confusing. There's a simple solution: define the function body grammar to only allow in{} and out{} blocks at the beginni

Re: Contract programming syntax

2009-04-08 Thread Christopher Wright
Denis Koroskin wrote: On Thu, 09 Apr 2009 00:51:49 +0400, Christopher Wright wrote: bearophile wrote: But isn't a syntax like the following better? To me it looks more logic, because in{} and out(){} are part of the function, and there's no need of a special syntax for the body (and the 'bo

Re: Contract programming syntax

2009-04-08 Thread Jarrett Billingsley
On Wed, Apr 8, 2009 at 5:32 PM, Frits van Bommel wrote: > > Not technically true -- contract can contain more than raw asserts. > For example, it might contain a non-trivial loop (such as a foreach which > calls a virtual opApply) which may be hard for the compiler to optimize out > even if it can

Re: Contract programming syntax

2009-04-08 Thread Frits van Bommel
Jarrett Billingsley wrote: On Wed, Apr 8, 2009 at 4:51 PM, Christopher Wright wrote: No. This proposed syntax change is quite misleading. Contracts cannot access the function's local variables, but it looks like they can. Contracts are executed at particular times, but that syntax makes them lo

Re: Contract programming syntax

2009-04-08 Thread Denis Koroskin
On Thu, 09 Apr 2009 00:51:49 +0400, Christopher Wright wrote: bearophile wrote: But isn't a syntax like the following better? To me it looks more logic, because in{} and out(){} are part of the function, and there's no need of a special syntax for the body (and the 'body' keyword): long

Re: Contract programming syntax

2009-04-08 Thread Jarrett Billingsley
On Wed, Apr 8, 2009 at 4:51 PM, Christopher Wright wrote: > > No. This proposed syntax change is quite misleading. Contracts cannot access > the function's local variables, but it looks like they can. Contracts are > executed at particular times, but that syntax makes them look like they > execute

Re: Contract programming syntax

2009-04-08 Thread Derek Parnell
On Wed, 08 Apr 2009 10:46:19 -0400, bearophile wrote: > But isn't a syntax like the following better? To me it looks more logic, > because in{} and out(){} are part of the function, and there's no need > of a special syntax for the body (and the 'body' keyword): Yes! I've never been happen with

Re: Contract programming syntax

2009-04-08 Thread bearophile
Christopher Wright: >Contracts cannot access the function's local variables, but it looks like they >can.< You are right, thank you. Bye, bearophile

Re: Contract programming syntax

2009-04-08 Thread Christopher Wright
bearophile wrote: But isn't a syntax like the following better? To me it looks more logic, because in{} and out(){} are part of the function, and there's no need of a special syntax for the body (and the 'body' keyword): long squareRoot(long x) { in { assert(x >= 0); } out

Re: Contract programming syntax

2009-04-08 Thread Robert Clipsham
dsimcha wrote: while(oldContractSyntaxSucks) { // Currently evaluates to true. vote++; } And always will do :D Proposed updated code: while(currentContractSyntaxSucks) { // Currently evaluates to true. vote++; } complainAboutSomethingElse();

Re: Contract programming syntax

2009-04-08 Thread dsimcha
== Quote from Nick Sabalausky (a...@a.a)'s article > "bearophile" wrote in message > news:gridbr$mv...@digitalmars.com... > >I like contract programming, it helps me avoid bugs. This is an example > >from the docs: > > > > long squareRoot(long x) > >in { > >assert(x >= 0); > >} > >

Re: My body is ugly (was Re: Contract programming syntax)

2009-04-08 Thread Alexander Pánek
Jarrett Billingsley wrote: Wed, Apr 8, 2009 at 1:02 PM, Denis Koroskin <2kor...@gmail.com> wrote: On Wed, 08 Apr 2009 20:01:46 +0400, Kagamin wrote: Don Wrote: I agree, the 'body' keyword is the most useless thing in the language. I find it makes functions much harder to read. I hate my bo

Re: My body is ugly (was Re: Contract programming syntax)

2009-04-08 Thread Robert Clipsham
Jarrett Billingsley wrote: Wed, Apr 8, 2009 at 1:02 PM, Denis Koroskin <2kor...@gmail.com> wrote: On Wed, 08 Apr 2009 20:01:46 +0400, Kagamin wrote: Don Wrote: I agree, the 'body' keyword is the most useless thing in the language. I find it makes functions much harder to read. I hate my bo

Re: My body is ugly (was Re: Contract programming syntax)

2009-04-08 Thread Jarrett Billingsley
Wed, Apr 8, 2009 at 1:02 PM, Denis Koroskin <2kor...@gmail.com> wrote: > On Wed, 08 Apr 2009 20:01:46 +0400, Kagamin wrote: > >> Don Wrote: >> >>> I agree, the 'body' keyword is the most useless thing in the language. I >>> find it makes functions much harder to read. >>> I hate my body. >> >> I

Re: Contract programming syntax

2009-04-08 Thread Bill Baxter
More agreement here. --bb On Thu, Apr 9, 2009 at 2:41 AM, Nick Sabalausky wrote: > "bearophile" wrote in message > news:gridbr$mv...@digitalmars.com... >>I like contract programming, it helps me avoid bugs. This is an example >>from the docs: >> >> long squareRoot(long x) >>    in { >>        a

Re: Contract programming syntax

2009-04-08 Thread Nick Sabalausky
"bearophile" wrote in message news:gridbr$mv...@digitalmars.com... >I like contract programming, it helps me avoid bugs. This is an example >from the docs: > > long squareRoot(long x) >in { >assert(x >= 0); >} > >out (result) { >assert((result * result) <= x && (resul

Re: My body is ugly (was Re: Contract programming syntax)

2009-04-08 Thread Denis Koroskin
On Wed, 08 Apr 2009 20:01:46 +0400, Kagamin wrote: Don Wrote: I agree, the 'body' keyword is the most useless thing in the language. I find it makes functions much harder to read. I hate my body. I second this. Thirded.

Re: My body is ugly (was Re: Contract programming syntax)

2009-04-08 Thread Kagamin
Don Wrote: > I agree, the 'body' keyword is the most useless thing in the language. I > find it makes functions much harder to read. > I hate my body. I second this.

My body is ugly (was Re: Contract programming syntax)

2009-04-08 Thread Don
bearophile wrote: I like contract programming, it helps me avoid bugs. This is an example from the docs: long squareRoot(long x) in { assert(x >= 0); } out (result) { assert((result * result) <= x && (result+1) * (result+1) >= x); } body { return ca