Hacker News new | ask | show | jobs
by variaga 2183 days ago
I'm sure it makes sense to someone well-versed in Rust syntax, but to an outsider like me that code looks like the kind of "line noise" that made me switch from perl to python.

The procedural 'if x.len == 3 and x[0] == x[1]' seems a lot clearer as to what is actually being tested.

2 comments

That code in the comment above isn't actually rust. It's a lisp, I believe.

In Rust, you'd write something more like:

  fn f(x: &[i32]) -> bool {
      match x {
          [x, y, _] if x == y => true,
          _ => false,
      }
  }
... and you could write

  fn f(x: &[i32]) -> bool {
      x.len() == 3 && x[0] == x[1]
  }
if you wanted. Honestly, I probably would.
A) this is in Racket, as that's the editor window I had up. B) your point is fair, one benefit of this is that it also binds names to things.