combined return and if statement like ruby #2195
Replies: 2 comments
-
I think #1785 is very close to what you're proposing (but there are quite a few proposals for similar features, so I'm not surprised it's not the one you found). I think the main issues with this proposal are:
|
Beta Was this translation helpful? Give feedback.
-
Instead of var value = somefunction();
if (value == null) {
return <error>;
} Just do var value = somefunction();
if (value == null) return <error>; Tada. |
Beta Was this translation helpful? Give feedback.
-
I was coming here to suggest a return if type statement and Github suggested a previous proposal from last summer.
I don't think the original poster on that proposal articulated the right solution, but one of the responses pointed out that Ruby has this construct already..
I guess I should do some research into how well this construct performs in Ruby, but I can say that my code is littered with things like this:
I believe that the code would be more readable if that code could look like this:
Thanks
Beta Was this translation helpful? Give feedback.
All reactions