‹ BackHN Continuity

Thread

What Zig felt like, coming from Rust

282 points · 351 comments · ksec

  1. sgarland · · focus · HN ↗
    From TFA, on combinators vs. loops:

        items.iter().enumerate().filter(|(_, i)| cond(i)).map(|(idx, i)| Pointer::idx(i, path, idx)).collect()
    
        while (i < cursors.len) {
            if (actual_index < arr.items.len) { cursors[i] = .{...}; i += 1; }
            else iteration.remove(i);
        }
    
    I’ve been slowly learning Rust, and this style is my main gripe against it, because I feel like I’m being gaslit. Its proponents praise its readability and ease of use, and just… no. It looks deranged. A simple loop is immediately obvious to anyone who’s programmed in any language. Even Python’s list comprehensions are loop-ish.
    1. matja · · focus · HN ↗
      .len doesn't work on a list (because it might mislead you about the efficiency of the operation if it did exist), so it's better to use iterators - so then you can change the underlying type without changing your code.

      But then, saying while "let Some(item) = iter.next()" everytime is tedious, so they give you .iter() - for any type that is efficiently iterable.

      Nothing stopping you using a manual loop that you need to update if you change the container type.

Open on Hacker News to reply ↗

Unofficial Hacker News client; not affiliated with Y Combinator.