|
|
|
|
|
by hryx
1211 days ago
|
|
In general Zig foregoes syntactic sugar and requires implementing higher-level APIs by composing primitives. But a new language feature is a candidate when it solves a use case that can't otherwise be solved, or opens up a path to more efficient code. Loris' blog post points out that the new for loops address the latter: > In the multi-sequence for loop version it’s only necessary to test once at the beginning of the loop that the two arrays have equal size, instead of having 2 assertions run every loop iteration. The multi-sequence for loop syntax helps convey intention more clearly to the compiler, which in turn lets it generate more efficient code. It also builds on existing properties of slices/arrays, rather than adding a new "enumerate primitive". |
|