by floating-io · 1y ago · 0 comments
foo ? { bar }
Reads naturally to me as "If foo then bar", when it's actually "If foo's error return exists then bar". I would suggest a different operator character, because this one reads wrongly IMO.Maybe it's just because I originally come from C, where `foo ? bar : baz` meant "if foo then bar else baz", but the fact remains...
func mayfail() error {
if snafu {
return errors.New("oops")
} else { return nil}
}
err := mayfail()
if err != nil { handle }
Same as `mayfail() ? handle : happypath` would behave with lazy evaluation. foo else { bar } { foo } catch { bar } { Foo }
catch (err) {}
catch (err2){}
throwfoo ?! { bar }
But, now we’re potentially confusing the “negation” and the “exclamation” meanings the bang symbol usually tries to communicate.
foo ?? { bar }
foo ?/ { bar }
foo ?: { bar }
foo ?> { bar }
foo ||> { bar }
Im not sure I like the idea at all though. It seems like a hack around a pretty explicit design choice. Although I do tend to agree the error handling boilerplate is kind of annoying.
foo or { bar }