Skip to content
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

A word about short-circuit evaluation #56

Open
paveloom opened this issue Jul 22, 2020 · 3 comments
Open

A word about short-circuit evaluation #56

paveloom opened this issue Jul 22, 2020 · 3 comments

Comments

@paveloom
Copy link
Contributor

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>
@omus
Copy link
Contributor

omus commented Jul 22, 2020

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.

@oxinabox
Copy link
Member

oxinabox commented Jul 22, 2020

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

@omus
Copy link
Contributor

omus commented Jul 28, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants