Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Yeah, that's just if as an expression, replacing the ?: operator. Compare to

  return (value >= radix) ? error.InvalidChar : value;


I actually prefer a ternary arrangement that lets you chain arbitrary such expressions like a truth table:

    return (value >= radix) ? error.InvalidChar:
           (comeCondition)  ? error.OtherError:
           ...
                              value;


I like doing that too, but the Zig syntax doesn't prevent that kind of arrangement, just makes it a bit wider.

    return if (value >= radix) error.InvalidChar else
           if (comeCondition)  error.OtherError  else
           ...
                               value;
or maybe this, but it seems uglier to me:

    return if      (value >= radix) error.InvalidChar
           else if (comeCondition)  error.OtherError
           ...
           else                     value;




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: