Style preferences on usage of 'return'
- Dominant language
- Java
- Stars
- 14.9k
- Forks
- 3.5k
- Avg merge
- 19h 14m
- Merged PRs (30d)
- 63
Description
Proposal:
- reject use of single explicit return
- if a method uses multiple returns, then all returns must be explicit.
Example:
```
# Use implicit return
def foo
do
some
stuff
3 # implicit return
end
```
And the multiple return:
```
def foo
if some_condition
return 3
end
do
some
stuff
return 4 # explicit return here because we have explicit return elsewhere in this method.
end
```
Questions:
- Should we allow returns from a conditional:
``` ruby
def foo
if condition
3
else
4
end
end
```
In the above case, what is "returned" is not really obvious, especially if have a style that doesn't have an `else` then the `if ...` implicit return is nil!
Contributor guide
Assessment
This issue has not been assessed yet.