5 ms·
The reason for <> instead of [] is that both are just as ambiguous to Rust's grammar, and that <> is, unfortunately, more-or-less the industry standard (C++, Ja
by kibwen 12y ago
The reason for <> instead of [] is that both are just as ambiguous to Rust's grammar, and that <> is, unfortunately, more-or-less the industry standard (C++, Java, and soon Swift). I would personally prefer something akin to D's generic syntax (but with a different symbol, since the exclamation point already has meaning in Rust).
The reason for using :: instead of . for paths is because the Rust developers did not want to conflate path lookup and field lookup, which would obscure the runtime costs of indirection. (This is also the same reason why you can't omit the parens when calling a method with no arguments: a field lookup and a method call have wildly different runtime costs.)
- wtetzner 12y agoHonestly, it's kind of sad that things are chosen because they're industry standard, instead of how good/nice they are. After using Scala, I think that []'s are much easier on the eyes than <>'s.
- kibwen 12y agoWhen designing a language, you have to decide which hills are worth dying on. Uglier it may be, but if using <> makes our syntax more immediately recognizable to C++ developers, then we have a better chance of succeeding in bringing safety to the low-level niche where C and C++ reign supreme. Don't worry, once Rust has established a foothold here, then we can start designing the pretty language that will usurp it. :)
- eklavya 12y agoI really really hope it changes to [] in future. I am scared of the code with lots of <>, I don't know why but I lose context.
- frowaway001 12y agoI agree with that. Having worked with languages which use <> and Scala, [] are just magnitudes more readable when expressing the same types.
- bjz_ 12y agoI hate the `<>`s, but the semantics are enticing enough for me to do all of my current personal projects in Rust. I would love Haskelly syntax, but life is never perfect... maybe somebody will make a pre-processor or something! Haha.
- wtetzner 12y agoI agree, it's not a deal-breaker. It's just that freezing something into a language forever because it's easier for someone just starting out feels wrong. Once you're familiar with the language, you have to deal with the ugliness forever.
- eklavya 12y agoThanks for shedding the light. I really really wish they had chosen [] instead of <>. I use Scala and I have fallen in love with how clean [] looks. Good to know the reasoning behind ::. Waiting for Rust 1.0, after it gets released it's Scala for JVM and Rust for everything else (except Qt) :P
- masklinn 12y agoHere's a recent RFC closed by its author on the subject: https://github.com/rust-lang/rfcs/pull/148 https://github.com/rust-lang/rfcs/pull/148 (a big issue with []-generics is that they're easy to confuse with indexing/slicing to a human. <> may look noisy, but it's harder to confuse it with comparisons)
- Dewie 12y agoWhat I like about Scala is the use of () for indexing arrays. It feels like a more uniform syntax - indexing an array is conceptually like calling a function from int to elements of the array - and I guess it reduces parsing ambiguity w.r.t. generics. Though apparently this couldn't be used in Rust, since they want both traits for indexing ( [] ) and calling like a function ( () ) on types that implement those respective traits.
- dbaupp 12y ago`()` is now overloadable, so one could implement that operators for arrays/vectors/slices to get indexing via ().
- eddyb 12y agoNot `map[k] = v;`, which is deal breaker.
- dbaupp 12y agoOther languages don't offer indexing sugar at all, so even minimal sugar for retrieving elements might be nice. There are however, more significant road blocks, like how to handle returning references (basically, we would be left in a similar situation to the current Index trait, which has its uses, but isn't what most indexing should do).