JuliaDiff / BlueStyle

A Julia style guide that lives in a blue world
Creative Commons Zero v1.0 Universal
492 stars 34 forks source link

How to wrap chained short-circuiting logic operations? #82

Open nickrobinson251 opened 3 years ago

nickrobinson251 commented 3 years ago

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?

omus commented 3 years ago

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