www.digitalmars.com         C & C++   DMDScript  

D - Parentheses for assert

reply Piotr Fusik <Piotr_member pathlink.com> writes:
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.
Mar 12 2004
parent reply J Anderson <REMOVEanderson badmama.com.au> writes:
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/
Mar 12 2004
next sibling parent =?ISO-8859-1?Q?Sigbj=F8rn_Lund_Olsen?= <sigbjorn lundolsen.net> writes:
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.)
Mar 12 2004
prev sibling parent reply Piotr Fusik <Piotr_member pathlink.com> writes:
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.
Mar 13 2004
next sibling parent reply "C. Sauls" <ibisbasenji yahoo.com> writes:
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
Mar 13 2004
parent reply J Anderson <REMOVEanderson badmama.com.au> writes:
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/
Mar 13 2004
parent reply Piotr Fusik <Piotr_member pathlink.com> writes:
 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.? ;-))
Mar 14 2004
parent "Matthew" <matthew stlsoft.org> writes:
"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.? ;-))
Mar 14 2004
prev sibling parent Manfred Nowak <svv1999 hotmail.com> writes:
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.
Mar 15 2004