I tend to agree. Also in Kotlin it tends a bit more readable because the function return type is postponed.
IMO little is added by the proposed syntax extension. p On Tue, Mar 20, 2018 at 12:20 PM, mg <mg...@arscreat.com> wrote: > Am having a migraine right now so hard to concentrate / think straight but > it seems all that syntax does is getting rid of a single character ? > > Integer truth() { 42 } > > could then be written as > > Integer truth() = 42 > > > or > > String hello(String name) { "Hello $name" } > > String hello(String name) = Hello $name" > > (why did you use a return keyword in your sample ?) > > I dont see an improvement in readability here - the main "advantage" is > that curly braces are annoying to input on non-US keyboard layouts ;-) > > mg > > > > -------- Ursprüngliche Nachricht -------- > Von: Cédric Champeau <cedric.champ...@gmail.com> > Datum: 20.03.18 11:41 (GMT+01:00) > An: dev@groovy.apache.org > Betreff: [RFE] Methods as expressions > > Hi, > > One of the Kotlin features I really like is the short-hand notation for > simple expression methods: > > class Foo { > fun truth(): Integer = 42 > } > > For example, in Groovy, you write: > > @Controller("/") class HelloController { > > @Get("/hello/{name}") > String hello(String name) { > return "Hello $name" > } > } > > > but we could write: > > @Controller("/") > class HelloController { > @Get("/hello/{name}") > String hello(String name) = "Hello $name" > } > > > It's more concise and makes the "functional style" more readable. Is this > something Groovy users would appreciate? > >