jastrachan | 31 Mar 09:02 2004
Picon

Re: Minor syntax question.


On 30 Mar 2004, at 18:09, Mike Spille wrote:
> Bing, great examples.  I have a much clearer view of what's going on 
> here, thanks.  It seems to me it comes down to:
>
> 	1) Fix the syntax to allow (f.q)().
> 	2) Kill the () closure sugar, and force everyone to use call e.g. 
> f.q.call()
>
> One thing to keep in mind - the current sugar makes closures look like 
> method calls, and there is potential for confusion there.  It's easy 
> to imagine someone saying:
>
> 	f.something()
>
> and picking up a "something" method when they really meant:
>
> 	f.something.call();
>
> Even if (f.q)() was allowed, it might be a common mistake to forget 
> the extra set of parens.  This might not be a common sort of mistake, 
> so I don't know how much anyone should worry about this.
>
> I guess the question becomes - is it worthwhile to really have a 
> closure look like a method that can be invoked directly?  Or is there 
> value in forcing .call()?  I admit I'm not sure, but I lean towards 
> forcing .call() personally.  Closures aren't methods, and it seems 
> there's danger in making them look the same in some contexts.

Agreed. I'm thinking (2) might be the cleaner approach.

I confess to having doubts about the () syntax sugar on closures too. 
At least once I've been bitten with a clash between a closure variable 
name and a method name - at least if we did remove the closure calling 
syntax it'd remove this confusion.

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

Gmane