Thread overview
Parentheses for assert
Mar 12, 2004
Piotr Fusik
Mar 12, 2004
J Anderson
Mar 13, 2004
Piotr Fusik
Mar 13, 2004
C. Sauls
Mar 14, 2004
J Anderson
Mar 14, 2004
Piotr Fusik
Mar 14, 2004
Matthew
Mar 15, 2004
Manfred Nowak
March 12, 2004
Why the parentheses are required for the assert's parameter? It looks like using parentheses for return - some people do it. In Java, I'm used to writing assert without parentheses.


March 12, 2004
Piotr Fusik wrote:

>Why the parentheses are required for the assert's parameter?
>  
>
It's something inherited from C.

>It looks like using parentheses for return - some people do it.
>In Java, I'm used to writing assert without parentheses.
>
I guess that could be made optional but how much would we gain from this style change?

-- 
-Anderson: http://badmama.com.au/~anderson/
March 12, 2004
J Anderson wrote:

> Piotr Fusik wrote:
> 
>> Why the parentheses are required for the assert's parameter?
>>  
>>
> It's something inherited from C.
> 
>> It looks like using parentheses for return - some people do it.
>> In Java, I'm used to writing assert without parentheses.
>>
> I guess that could be made optional but how much would we gain from this style change?

It would look a lot more like *my favourite language* - isn't that the only reason worth paying attention to?

Cheers,
Sigbjørn Lund Olsen

(Beware: This post contains irony.)
March 13, 2004
>>Why the parentheses are required for the assert's parameter?
>>
>It's something inherited from C.
>
C's assert is a macro, not a language construct. If I understood well, strict compatibility with C at source level is not a design goal of D.

>>It looks like using parentheses for return - some people do it. In Java, I'm used to writing assert without parentheses.
>>
>I guess that could be made optional but how much would we gain from this style change?

1. Shorter code, easier to write and read.
2. No problems for people that are used to writing no parentheses after assert.
3. Consistency with return.


March 13, 2004
Comments imbedded:

Piotr Fusik wrote:
>>>Why the parentheses are required for the assert's parameter?
>>>
>>
>>It's something inherited from C.
>>
> 
> C's assert is a macro, not a language construct. If I understood well, strict
> compatibility with C at source level is not a design goal of D.

From the D specification, Overview, under "Features to Keep...":
 - The general look and feel of C/C++ will be maintained.

> 
>>>It looks like using parentheses for return - some people do it.
>>>In Java, I'm used to writing assert without parentheses.
>>>
>>
>>I guess that could be made optional but how much would we gain from this style change?
> 
> 
> 1. Shorter code, easier to write and read.

assert (someObj.member != someConst);
assert someObj.member != someConst;

Mm.

> 2. No problems for people that are used to writing no parentheses after assert.
> 3. Consistency with return.

What is the relationship between assert(); and return; though?  I don't remember there being any connection between the foundation contract statement and the procedure conclusion statement...

Personally I'm a fan of parenthesis in certain places... like if(), for(), foreach(), while(), assert(), and yes I've even been known to do return().

-C. Sauls
-Invironz
March 14, 2004
C. Sauls wrote:

> What is the relationship between assert(); and return; though?  I don't remember there being any connection between the foundation contract statement and the procedure conclusion statement...

Both will cause termination of the current function, although assert will cause termination of the current program as well.

-- 
-Anderson: http://badmama.com.au/~anderson/
March 14, 2004
>> What is the relationship between assert(); and return; though?  I don't remember there being any connection between the foundation contract statement and the procedure conclusion statement...
>
>Both will cause termination of the current function, although assert will cause termination of the current program as well.
>
.. and both take just one expression as a parameter, thus making the
parentheses redundant. The parentheses are needed for if() and like to make the
syntax unambiguous. For all the fans of parentheses out there, why not support
break(), continue() etc.? ;-))


March 14, 2004
"Piotr Fusik" <Piotr_member@pathlink.com> wrote in message news:c31ubr$t5t$1@digitaldaemon.com...
> >> What is the relationship between assert(); and return; though?  I don't remember there being any connection between the foundation contract statement and the procedure conclusion statement...
> >
> >Both will cause termination of the current function, although assert will cause termination of the current program as well.
> >
> .. and both take just one expression as a parameter,

so far. There is lots of work to do with asserts, and it is highly likely that there'll be multi-parameter versions coming along

thus making the
> parentheses redundant. The parentheses are needed for if() and like to
make the
> syntax unambiguous. For all the fans of parentheses out there, why not
support
> break(), continue() etc.? ;-))
>
>


March 15, 2004
Piotr Fusik wrote:

[...]
> 1. Shorter code,

What about locally inhibiting the usual LR lexical analysis? May allow even shorter code by not needing spaces  :-)

> easier to write and read.
[...]

Do you have an objective measure for `easy'?

So long.