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

What's syntactically obscure about Rust?

I only knew(and liked) C reasonably well before Rust. And nothing felt obscure when I started learning it.

I can only remember not getting what `||` meant (in the context of defining a closure without args). The positional meaning of `||` and `&&` is the only thing, I can recall right now, that can be considered obscure syntactically (for C developers at least) . They should have gone with literal `and`/`or` for the operators IMHO.



I suppose it can get a little silly when you mix closures without arguments and the logical 'or' operator', e.g.:

    // prints 'true'
    println!("{}", true||(||true)()||(||true)());
Of course you wouldn't actually do this unless you're being intentionally obscure. Another favorite of mine:

    // prints '()'
    println!("{:?}", (||||||||||())()()()()());
But I can't recall ever running into such silly code, in practice the closure syntax and logical or do not lead to confusion (imho, ymmv).


> in practice the closure syntax and logical or do not lead to confusion (imho, ymmv).

That's true. But put your self in the mind of a C developer looking at Rust code for the first time:

     if a || b {
       println!("True");
     }
Cool.

Then:

     thread::spawn(|| println!("Hello from a thread!"););
What? What is the logical or doing there?

----

IIRC, there are also cases where you have to write `& &` instead of `&&` to not confuse the compiler. That's a design/practical issue.

Both those issues would have been avoided if literal `and`/`or` were used.

I find it interesting how the only thing that momentarily confused me, as a C developer, about Rust syntax, was caused by Rust authors not wanting to syntactically deviate too much from C.




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

Search: