JuliaDiff / JuliaDiff/BlueStyle

Short-circuit logic used as control flow should only be used on a single line

Open
#72 6 comments 0 reactions 0 assignees View on GitHub

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.