Hacker News new | ask | show | jobs
by alfnoodles 2016 days ago
Ah. The biggest difference between ?/: and if/else is that ?/: is an expression (returns a value) and if/else are statements (a step/command/declaration/etc). You can build statements on top of CEL (lots do), but the core Common Expression Language (CEL) doesn't actually have them.

Note that python uses if/else for the ternary expression form as well: `a = b if c else d`

Though personally, I like to have the condition in the front, instead of in the middle.

1 comments

if/else doesn't have to be a statement:

    max = if a < b then b else a
You may also like `jq` syntax with `elif`s:

    if cond1 then res1 elif cond2 then res2 ... else res end