BlueStyle icon indicating copy to clipboard operation
BlueStyle copied to clipboard

A word about short-circuit evaluation

Open paveloom opened this issue 5 years ago • 3 comments

A little about the stylistic usage of this functionality is mentioned in the official documentation, but I would like to see this guide's position on what and when is preferable:

if ! <cond> <statement> end

or

<cond> || <statement>

paveloom avatar Jul 22 '20 10:07 paveloom

As a first pass I think:

<cond> || <statement>

is fine if it's within the line length and the statement isn't a compound statement (e.g. (...; ...; ...)). In all other scenarios:

if !<cond>
    <statement>
end

should be preferred.

omus avatar Jul 22 '20 20:07 omus

Sometimes I think it is also fine for multiline compound statements if wraping them in an if would lead to long indent.

Mostly I am thinking of testsets. Writing something like this testset with a giant if block around it would not be easier to read, it would just double the arond of indentation needed

oxinabox avatar Jul 22 '20 21:07 oxinabox

That's a good counter example. There are always exceptions to rules and that would be one here. Generally though I think the first pass I outlined is what we should promote as that's generally what should be used.

omus avatar Jul 28 '20 19:07 omus