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.
I have a confession… I don’t like
unless
— I find it confusing as I have to negate anif
statement in my head.A variation of
unless
that I really like is Swift’sguard
. It’s essentially a check with an early return. Unless the guard’s condition is true, it then forces you to return on theelse
.Here’s what it could look like with Orb:
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 likeguard
as that much more of mortal sin than addingunless
.Alternatives