Skip to content

Commit

Permalink
Add a style point on return statements (jump-dev#1721)
Browse files Browse the repository at this point in the history
* Add a style point on return statements

* Add motivation
  • Loading branch information
odow authored and mlubin committed Jan 3, 2019
1 parent 9483613 commit 687d960
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions docs/src/style.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,39 @@ Bad:
2(x + 1)
```

#### Return statements

To avoid situations in which it is unclear whether the author intended to return
a certain value or not, always use an explicit `return` statement to exit from a
function. If the return from a function is `nothing`, use `return` instead of
`return nothing`.

We make an exception for assignment-form one-line functions (`f(x) = 2x`).

Good:
```julia
foo(x) = 2x # Acceptable if one line
function foo(x)
return 2x
end
function foo(x)
x[1] += 1
return
end
```

Bad:
```julia
function foo(x)
2x
end
function foo(x)
x[1] += 1
return nothing
end
```


#### TODO: Line breaks

### Syntax
Expand Down

0 comments on commit 687d960

Please sign in to comment.