-
Notifications
You must be signed in to change notification settings - Fork 34
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
Short-circuit logic used as control flow should only be used on a single line #72
Comments
Example is incorrect: julia> true || false || false && println("it works!")
true |
A counter example which I am fine with: last_log == curr && debug(LOGGER) do
"Consuming input from connection $(jl_conn.conn). Stand by for landing.")
end I think I'm okay with using short-circuit logic on multiple lines if the portion that spans multiple lines forms is contained within a block. e.g.: condition && begin
...
end |
😆 Oooops (is_red(x) || is_blue(x) || is_yellow(x)) && println("It's a primary colour!") But i gues you get the point: we're fine with chaining |
I think i agree with this too 👍 (But would be okay recommending against it if other people felt strongly) |
Here's a specific case (from PkgTemplates) where we need to decide what style we want and what the formatter should do: julia> str = """
p.project && t.julia < v"1.2" && @warn string(
"Tests: The project option is set to create a project (supported in Julia 1.2 and later) ",
"but a Julia version older than 1.2 ((t.julia)) is supported by the template",
)
""";
julia> println(str) # starting code
p.project && t.julia < v"1.2" && @warn string(
"Tests: The project option is set to create a project (supported in Julia 1.2 and later) ",
"but a Julia version older than 1.2 ((t.julia)) is supported by the template",
)
julia> println(format_text(str, BlueStyle())) # formatted code with JuliaFormatter v0.9.7
p.project &&
t.julia < v"1.2" &&
@warn string(
"Tests: The project option is set to create a project (supported in Julia 1.2 and later) ",
"but a Julia version older than 1.2 ((t.julia)) is supported by the template",
) |
I think this looks reasonable: p.project && t.julia < v"1.2" && @warn begin
"Tests: The project option is set to create a project (supported in Julia 1.2 and later) " *
"but a Julia version older than 1.2 ((t.julia)) is supported by the template"
end |
This came up over at JuliaDatabases/LibPQ.jl#197 (comment)
e.g. for
&&
and||
(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:
i.e.
Unlike ternary conditionals
?:
, chaning short-circuit logic as conditionals is fine e.g. this is okayThe text was updated successfully, but these errors were encountered: