Open nickrobinson251 opened 4 years ago
is_red(x) || is_blue(x) || is_yellow(x) && println("It's a primary colour!")
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
Example is incorrect
😆 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 &&
/||
to the extent they fit on 1 line
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
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 https://github.com/invenia/LibPQ.jl/pull/197#discussion_r492802769
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 okay