jastrachan | 22 Apr 10:29 2004
Picon

Re: Parens and Parameters

FWIW I'm starting to lean towards the parenthesis becoming mandatory, 
especially if it fixes some of the ambiguities Chris found in the 
parser - apart from when syntax sugar is used to pass closures into a 
method (again as long as no ambiguities arise).

foo.methodWithZeroArgs()
foo.methodWithOneArg(x)
foo.methodWithOneClosure { ... }
foo.methodWithOneParamAndClosure(x) { ...}
foo.propertyAccess

Apart from closure passing syntax sugar the main time I like the 
optional parenthesis is

     println "hello world!"

type statements. Though I guess

     out << "hello world!"

is almost as simple.

Though we should debate this in detail, going into every nook and 
cranny, ambiguity and edge case as part of the JSR which should kick 
off in earnest by next week.

On 22 Apr 2004, at 07:19, John Wilson wrote:
> On 21 Apr 2004, at 22:14, Joe Germuska wrote:
>
>>> consider
>>>
>>> c  =  { "hello"}
>>>
>>> c = {'hello"}()
>>>
>>> Just because something can be called with no parameters doesn't mean 
>>> that you always want to call it.
>>
>> This is exactly right; also, while Groovy shouldn't just be a 
>> copy-cat, this is a very standard syntax in scripting languages that 
>> allow you to treat methods as objects -- cf. JavaScript, Python, 
>> probably lots of others...
>>
>> However, if this causes people consternation, I'd suggest just making 
>> parentheses required for all method calls -- I actually believe that 
>> omitting parentheses often makes code harder to read, not easier.
>>
>
> I'm inclining to that view myself with the exception that a function 
> taking a single closure could usefully ommit the parens:
>
> f {
> }
>
> is equivalent to
>
> f ({
> })
>
> and
>
> f() {
> }
>
>
> John Wilson
> The Wilson Partnership
> http://www.wilson.co.uk
>
> _______________________________________________
> groovy-user mailing list
> groovy-user@...
> http://lists.codehaus.org/mailman/listinfo/groovy-user
>
>

James
-------
http://radio.weblogs.com/0112098/

Gmane