Skip to content

Commit

Permalink
more clear rendition of in-the-wild when conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
Zachary Jones committed Mar 30, 2015
1 parent ad68059 commit 2aee498
Showing 1 changed file with 32 additions and 23 deletions.
55 changes: 32 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,43 +140,52 @@ You can generate a PDF or an HTML copy of this guide using
end
```

* put multi when conditions on separate lines
* put multiple when conditions on separate lines
particularly where the conditions form long, complicated lines

```Ruby
# good
case token
when :star_op
stack.pop * stack.pop
when :slash_op
stack.pop / stack.pop
when :minus_op
also_calculate_that
stack.pop - stack.pop
when :plus_op,
:plus_plus_op
stack.pop + stack.pop
when :int_literal
token.value
end
when :star_op
stack.pop * stack.pop
when :slash_op
stack.pop / stack.pop
when :minus_op, :plus_op
also_calculate_that
stack.pop - stack.pop
when MyModule::SomeDomain::BETA_USERS,
MyModule::SomeDomain::INTERNAL_RELEASE
stack.pop + stack.pop
when :int_literal,
:some_complicate_explicit_name,
:graduate_borrowers_with_arms,
:str_interpolated
token.value
end
```

which reads better than
Though better control of primary domain references should be exercised, this style offers a solution for some 'in the wild' situations. It reads better than:

```Ruby
# bad
case token
when :star_op
stack.pop * stack.pop
when :plus_op, :plus_plus_op
stack.pop + stack.pop
when :int_literal, :str_literal, :str_interpolated
token.value
end
when :star_op
stack.pop * stack.pop
when :slash_op
stack.pop / stack.pop
when :minus_op, :plus_op
also_calculate_that
stack.pop - stack.pop
when MyModule::SomeDomain::BETA_USERS, MyModule::SomeDomain::INTERNAL_RELEASE
stack.pop + stack.pop
when :int_literal, :some_complicate_explicit_name, :graduate_borrowers_with_arms, :str_interpolated
token.value
end
```

Where the 'bad' example also has the issue of cause the entire when line to diff when one of the conditions is changed or updated
The 'bad' example also has the issue of cause the entire when line to diff when one of the conditions is changed or updated


* Use empty lines between `def`s and to break up a method into logical
Expand Down

0 comments on commit 2aee498

Please sign in to comment.