Parenthesis

NN nn-mail at bk.ru
Fri Dec 29 02:23:54 PST 2006


== Quote from John Demme (me at teqdruid.com)'s article
> NN wrote:
> > What about removing unuseful parenthesis in 'if', 'for', 'while' ?
> > E.g. instead of:
> > if(a == b)
> > {
> >   while(c)
> >   {
> >      ...
> >   }
> > }
> > We can write:
> > if a == b
> > {
> >   while c
> >   {
> >      ...
> >   }
> > }
> >
> > If someone writes parenthesis the code will compile too.
> > So this is almost backwards compatible feature.
> >
> > What about 'if' with one expression ?
> > Almost everyone writes curly brackets for more than one expression, so
> > there they will be always written, and there will be no bugs.
> I don't like this idea- parens are a good thing.  There is one paren-related
> change I'd like to see, though.  I'd like to be allowed to put a '!' right
> before the parens, so I could do
> if !(/*some long expression*/)
>         foo();
> instead of
> if (!(/*some long expression*/))
>         foo();

And what about
if((p = f(a, b)) < 0) foo();

It can be simplified to:
if (p = f(a, b)) < 0
{
  foo();
}

> The extra set of parens always bothered me.  Does this create any sort of
> ambiguity?
Curly brackets will make no ambiguity :)



More information about the Digitalmars-d mailing list