Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Guidance on parentheses, more is better #3

Merged
merged 1 commit into from
Sep 24, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 47 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,17 +114,16 @@ evolves.

## Syntax

* Use `def` with parentheses when there are arguments. Omit the
parentheses when the method doesn't accept any arguments.
* Always `def` with parentheses.

```Elixir
# bad
def some_method()
def some_method
# body omitted
end

# good
def some_method
def some_method()
# body omitted
end

Expand Down Expand Up @@ -192,6 +191,50 @@ evolves.
f(3 + 2) + 1
```

* Use parentheses in function calls, especially inside a pipeline.

```Elixir
# bad
f 3

# good
f(3)

# bad and parses as f(3 |> g), which is not what you want
f 3 |> g

# good
f(3) |> g()
```

* Omit parentheses in macro calls when a do block is passed.

```Elixir
# bad
quote(do
foo
end)

# good
quote do
foo
end

* Optionally omit parentheses in function calls (outside a pipeline) when
the last argument is a function expression.

```Elixir
# good
Enum.reduce(1..10, 0, fn x, acc ->
x + acc
end)

# also good
Enum.reduce 1..10, 0, fn x, acc ->
x + acc
end
```

## Naming

* Use `snake_case` for symbols, methods and variables.
Expand Down