BlueStyle icon indicating copy to clipboard operation
BlueStyle copied to clipboard

How to wrap chained short-circuiting logic operations?

Open nickrobinson251 opened this issue 4 years ago • 1 comments

If we have code the goes over the line limit, like

if primal_name isa Symbol || Meta.isexpr(primal_name, :(.)) || Meta.isexpr(primal_name, :curly)
    # do stuff
end

How should that be wrapped?

I think our preference would be for something like this

if (
    primal_name isa Symbol ||
    Meta.isexpr(primal_name, :(.)) ||
    Meta.isexpr(primal_name, :curly)
)
    # do stuff
end

does that seem right?

nickrobinson251 avatar Feb 08 '21 18:02 nickrobinson251

Yes, that seems reasonable. I'm rather flexible on this so if you're over the line limit you could still allow multiple conditions one line and wrap it where necessary. In some cases where you are mixing && and || you may want to break it up in some other logical form

omus avatar Feb 08 '21 19:02 omus