Re:Zig: a system language which prioritizes optimality, safe...
by perfunctory on Monday August 29, 2016 @03:23AM
(#12380541)
I don't think this has anything to do with "suffix-if".
[ Parent
| on HN ]
Re:Zig: a system language which prioritizes optimality, safe...
by web007 on Monday August 29, 2016 @05:10AM
(#12380822)
True, which only makes my poorly-targeted point on bad parsability.
Reading the code requires backtracking around a conditonal control statement, and in a format more verbose than ternary. Most places I've worked have bans or limits on ternary to single boolean cases for the same reason: It's hard for people to understand the control flow of operations around conditional assignment. A new language that lets you perpetuate painful code isn't helping as much as it could.
It's much simpler for people to parse the more verbose case with an IF and two return blocks, and the compiler shouldn't care since it can generate the same code either way.
Re:Zig: a system language which prioritizes optimality, safe...
by gliptic on Monday August 29, 2016 @06:16AM
(#12380993)
I think that is quite subjective. I prefer this version with one return. I don't want more returns than necessary, and I want them as far up in the nesting as possible so they are easy to see. Returns are, after all, control-flow altering.
Re:Zig: a system language which prioritizes optimality, safe...
by majewsky on Monday August 29, 2016 @05:01AM
(#12380802)
Yeah, that's just if as an expression, replacing the ?: operator. Compare to
return (value >= radix) ? error.InvalidChar : value;
Re:Zig: a system language which prioritizes optimality, safe...
by naasking on Monday August 29, 2016 @07:55AM
(#12381272)
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;
Re:Zig: a system language which prioritizes optimality, safe...
by drjeats on Monday August 29, 2016 @12:39PM
(#12383099)
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;