Hacker News new | ask | show | jobs
by fluffything 2266 days ago
C++ requires using the template keyword to disambiguate, i.e., one has to write `foo.template bar<22>()` as opposed to `foo.bar<22>()` (did you mean `(foo.bar < 2*2) > ()` ?).

The main reason Rust meta-programming is so much better than D and C++ is that Rust has an LL(k) grammar that's trivial to parse into ASTs that can be easily manipulated.

That feature alone is definitely worth the annoyance of having to use an editor that types `{}` for you when inputting a constant expression. It's the same with removing the `::` in `::<>` - can be done, but the costs are not worth the ergonomic improvement.

That is, I don't think the claim that the braces are redundant is correct - they are there for a reason: to keep a simple grammar, which happens to be one of the most important Rust features that everybody uses every day (every single proc macro uses this feature, that includes the `println!` in `println!("Hello World")` Rust examples).

1 comments

Removing redundancy is not always a good idea, but the braces are redundant.
Can you elaborate? If you remove the braces, you break one of Rust's most important language features, an LL(2) grammar.

That is, those braces give Rust an LL(2) grammar, and therefore, are not redundant.

If you know how to preserve the LL(2) grammar in Rust while removing those braces, please explain why, since the answer would revolutionize many fields of computer science.

The braces are redundant because they do not introduce any new information, which is the definition of being redundant.

Whether the resulting grammar is or not LL(2) is orthogonal.