February 28, 2004
I feel like the in/out contracts for functions look kind of strange right now without a set of braces around the entire thing. I know
that in/out contracts around plain sections of code is planned for
the future, but to me it seems like all contracts should be treated
like that.

currently (from spec):

long square_root(long x)
  in
  {
    assert(x >= 0)
  }
  out
  {
    assert((result * result) == x);
  }
  body
  {
    return math.sqrt(x);
  }


This seems prettier to me:


long square_root(long x)
{
  in
  {
    assert(x >= 0)
  }
  out
  {
    assert((result * result) == x);
  }
  body
  {
    return math.sqrt(x);
  }
}


Or even leave out the "body" entirely:


long square_root(long x)
{
  in
  {
    assert(x >= 0);
  }
  out
  {
    assert((result * result) == x);
  }

  return math.sqrt(x);
}

I know its nitpicking, but it seems like the syntax as it stands
might be a problem for automatic code formatting, and maybe
others here think that its kind of strange looking too. On the
other hand, if there are reasons why it is currently the way it
is, I'd like to hear them.

-Jon
February 28, 2004
Jon wrote:
> I feel like the in/out contracts for functions look kind of strange right now without a set of braces around the entire thing.

I kidn of like it this way.  All the pieces are on equal footing.  And C++ already has function try blocks that are formatted exactly the same way so I doubt pretty-printers will have much trouble with the syntax.


Sean