JuliaDiff / JuliaDiff/BlueStyle
Short-circuit logic used as control flow should only be used on a single line
Nobody has claimed this yet.
- Dominant language
- No language data
- Stars
- 519
- Forks
- 34
- PR merge metrics
- No merged PRs in 30d
Description
This came up over at https://github.com/invenia/LibPQ.jl/pull/197#discussion_r492802769
e.g. for && and ||
# Yes
if last_log == curr
debug(LOGGER, "Consuming input from connection $(jl_conn.conn). Stand by for landing.")
end
# No, over line limit:
last_log == curr && debug(LOGGER, "Consuming input from connection $(jl_conn.conn). Stand by for landing.")
# No, use an `if` conditional:
last_log == curr &&
debug(LOGGER, "Consuming input from connection $(jl_conn.conn). Stand by for landing.")
(aside: we may want to use a different example in the guide, given #59 is an open question)
This is consistent with out current advice on ternary conditionals:
Ternary operators (?:) should generally only consume a single line
i.e.
# Yes:
foobar = if some_big_long_really_long_expr_here_long == 2
barrrr_more_long
else
bazzz_also_not_short
end
# No:
foobar = some_big_long_really_long_expr_here_long == 2 ? barrrr_more_long : bazzz_also_not_short
Unlike ternary conditionals ?:, chaning short-circuit logic as conditionals is fine e.g. this is okay
is_red(x) || is_blue(x) || is_yellow(x) && println("It's a primary colour!")
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the guide's current ternary-operator advice and the surrounding control-flow guidance. Update the guide to state that short-circuit control flow should stay on one line, include the proposed examples, and consider whether the example should change in light of #59.】【。
Written by the indexing model from the issue text.
Assessment
- Tech stack
- julia
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 38/100