Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!.POSTED!not-for-mail From: BGB Newsgroups: comp.lang.java.programmer Subject: Re: new Java lambda syntax Date: Sun, 11 Sep 2011 14:08:15 -0700 Organization: albasani.net Lines: 96 Message-ID: References: <9j3vj8-aqe.ln1@news.simpsonst.f2s.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.albasani.net fc1UBybMKngiAU5z28kxIspUwcn1VBueUygIigx49bmYO1vmCwf9wOfrHan7Q1FVJl0oFerkB1K5eX3Q085V5w== NNTP-Posting-Date: Sun, 11 Sep 2011 21:08:07 +0000 (UTC) Injection-Info: news.albasani.net; logging-data="Ety9cra37tSgM3R/H1RXtwGI8uC4CD2ZO3YjeMLnzYmm7KOsO8AUCb9ejdN53RwbWilzaT0HS8iilkNY786bgtKE/Y+BAEnaePK08vfFywMbwzwUE0d5pzURQGt10NmT"; mail-complaints-to="abuse@albasani.net" User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0.2) Gecko/20110902 Thunderbird/6.0.2 In-Reply-To: Cancel-Lock: sha1:uF+SGWdPOZxxqRVmGlqbHCBu9ZU= Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:7822 On 9/11/2011 12:14 PM, Steven Simpson wrote: > On 11/09/11 19:08, BGB wrote: >> I would have also liked to see lexical variable capture. >> FFS, I added this (along with closures) to a C compiler before, can't >> be too hard > > At this stage, I don't think the issue is how, but whether/when to > permit it. > > All suggestions for how seem to come down to boxing: > > * arrays of length 1 > * hidden local classes > * AtomicInteger, etc > > (If there were any others, I didn't understand them.) > > The options for when/whether have been: > > * never > * always > * when a local is tagged with @Shared, public or similar > * when the SAM parameter is tagged with @Callback, @Block or similar > > They've gone for 'never' because it's sufficient to meet their primary > goals of supporting concurrent APIs, especially on collections, and they > want to encourage good concurrent practices. They can still look at the > other options later - it would be harder to withdraw an advanced > feature, having discovered it was a bad idea. > fair enough, just I guess this makes it a bit different from several other languages with closures (such as JS). >> having spent more of my time using languages with much nicer >> first-class functions (yes, I will include C here, as well as >> JavaScript and similar...), having to have extra syntax (both to >> declare and use these types) is IMO lame. >> >> in all cases, one would type "obj(args)". >> >> idiomatic for Java or not, the more compact declarations and >> invocations are more what people who use most other languages are >> likely to expect (and ideally the compiler can be smart enough to >> figure out what "obj(args)" with a SAM means). > > Lambda declarations are already quite compact, with type inference > helping in most cases. > > new Thread(() -> { doSomething(); }).start(); // Runnable implied > > For invocations, having to type obj.run() instead of obj() is hardly > onerous. Plus, invocations will be much rarer than lambda declarations. > Also note that the invocation site is unaware of whether the object is a > lambda. > yes, ok. however... whether or not it is a lambda could be made a side issue: Runnable obj; ... obj(); could be made to "just work" (with either a lambda, or with an interface). it may not matter much for things like traditional callbacks/..., but it could make more of a difference if people want something like assignable methods. being able to type: "obj.someAssignableMethod();" would be a little nicer looking than "obj.someAssignableMethod.run();". even if, yes, this is all basically just syntax sugar. (among other things, like getter/setter properties, ...). also, misc: in my own language, the above thread example could be written: async { doSomething(); } ( I had considered making the braces optional, but at the moment this poses more subtle issues. in the above context, async serves as a thread-creation keyword. ) not that I think syntax sugar is a huge issue though, as (after all) I still do much of my programming in C (peoples' value-judgements against C aside...). or such...