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

Add guard? #29

Open
RoyalIcing opened this issue May 5, 2024 · 0 comments
Open

Add guard? #29

RoyalIcing opened this issue May 5, 2024 · 0 comments

Comments

@RoyalIcing
Copy link
Owner

RoyalIcing commented May 5, 2024

I have a confession… I don’t like unless — I find it confusing as I have to negate an if statement in my head.

A variation of unless that I really like is Swift’s guard. It’s essentially a check with an early return. Unless the guard’s condition is true, it then forces you to return on the else.

guard len > 0 else {
  return false
}

Here’s what it could look like with Orb:

# Rather than:
unless len > 0 do
  return(0)
end

# Instead write:
guard do
  len > 0
else
  return(0)
end

I’d be open to using unless if there’s some way to make it more readable.

Note that WebAssembly doesn’t have the concept of unless, only Elixir does. So I don’t see adding a new concept that WebAssembly doesn’t have like guard as that much more of mortal sin than adding unless.

Alternatives

unless(len > 0, return: 0)
return(0 when not len > 0)
@RoyalIcing RoyalIcing changed the title Add guard Add guard? Jun 13, 2024
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

1 participant