On 16.05.2017 20:57, H. S. Teoh via Digitalmars-d wrote:
On Tue, May 16, 2017 at 08:43:01PM +0200, Timon Gehr via Digitalmars-d wrote:
On 16.05.2017 20:06, Andrei Alexandrescu wrote:
On 05/16/2017 01:59 PM, Random D user wrote:

int foo()
in
{
}
out
{
}
do
{
  bar();
}

Can't deny I like that. -- Andrei

Beats options 2 and 3.

To me, it's actually worse, because now you have a visual conflation
with do-loops.


It's worse than option 1, but not worse than options 2 and 3. I prefer a visual conflation with do loops over a visual conflation with any of the constructs having 'function' in it, and I'm saying no to this:

...
{

}{

}

Overall, what I don't like about contract syntax is that it is so
unbearably verbose.

It's quite verbose, but certainly not unbearably so.

It's not just the in and out blocks and the (IMO
redundant)  marking of the function body;

There are many redundant elements in the D grammar. It's not a bad thing per se.

it's also the repeated
'assert's that occur in the in and out blocks.

        int foo(T, U)(T t, U u)
        if (sigContraints!T && sigConstraints!U)
        in
        {
                assert(t > 0 && u < 10);
        }
        out(val)
        {
                assert(val > 1 && val < 5);
        }
        body
        {
                // function body here
        }

I understand this DIP is only to address the `body` part of this ugly
verbosity,

Actually, the goal of the DIP is to make 'body' not a keyword. Nothing more.

but imagine how much better it would be if we could write
something like this instead:

        int foo(T, U)(T t, U u)
        if (sigConstraints!T && sigConstraints!U)
        in (t > 0 && u < 10)
        out(foo > 1 && foo < 5 )
        {
                // function body here
        }

This is just tentative example syntax, of course.  We can argue over its
fine points later, but the point is that the current syntax is far too
verbose, and can easily be reduced to half the number of lines.  Merely
changing `body` to `do` does nothing to address this, and seems to me to
be just more useless churn, replacing one bit of verbosity with another
bit of verbosity.

It's a good option to have, but D is not an expression-based language, so this can be painful, as you cannot declare intermediate variables nor use statements.

(Not to mention the IMO very ugly syntax clash with
do-loops, which will reduce code readability even more.)
...

Do you think your new syntax is significantly more readable? (Just curious.)

Reply via email to