Daniel, -1. In my personal experience this happens very rarely, not worth a special support in the language by far. Almost all similar cases for me are covered by simple
def foo() { ... ... bar()?:defaultValue } and the cases where this is not adequate, either due a non-null false return value which should be returned instead of the default, or due to a non-trivial code needed at //! below, in my code almost never happen. Contrariwise, if you are about to improve the language for simplicity and easiness of returns, you definitely should consider allowing returning void from a void method — this should be a completely valid code (as is e.g., in C): void foo() { ... } void bar() { return foo() } As always, of course, YMMV. All the best, OC > On 25 Jul 2020, at 20:55, Daniel Sun <sun...@apache.org> wrote: > > Hi all, > > We always have to check the returning value, if it match some condition, > return it. How about simplifying it? Let's see an example: > > ``` > def m() { > def r = callSomeMethod() > if (null != r) return r > //! > return theDefaultResult > } > ``` > > How about simplifying the above code as follows: > ``` > def m() { > return? callSomeMethod() //! > return theDefaultResult > } > ``` > > Futhermore, we could make the conditional return more general: > ``` > def m() { > return(r -> r != null) callSomeMethod() // we could do more checking, e.g. > r > 10 > return theDefaultResult > } > ``` > > Any thoughts? > > Cheers, > Daniel Sun