elastic / elastic/logstash

Style preferences on usage of 'return'

Open
#2,569 2 comments 0 reactions 0 assignees View on GitHub
ruby style guide
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.