3 ms·
I'd like to add the "Bastion of the Turbofish", which is my personal favorite: https://github.com/rust-lang/rust/blob/master/src/test/ui/bastion-of-the-turbofis
by Zababa 6y ago
I'd like to add the "Bastion of the Turbofish", which is my personal favorite: https://github.com/rust-lang/rust/blob/master/src/test/ui/bastion-of-the-turbofish.rs https://github.com/rust-lang/rust/blob/master/src/test/ui/ba...
- iudqnolq 6y agoTo explain this, since it took me a minute: Rust has a syntax called "turbofish" for disambiguating ambiguous generic calls. (Coined by Anna Harren on twitter, the first reply is an illustration from Karen Rustad Tölva, the inventor of Ferris [1]). Although Vec is generic over any item type, you can normally just write let foo = Vec::new(); If you're doing something complicated where the compiler can't infer the type, you instead use the turbofish syntax let foo = Vec::<u32>::new(); Some people hate this syntax. One of the better arguments I've seen against it comes (I think) from ManishEarth, who points out that it's very hard for the compiler to detect that incorrect attempts at writing a turbofish are in fact attempts at the turbofish and offer help. That test case (minus some excellent poetry) is let (oh, woe, is, me) = ("the", "Turbofish", "remains", "undefeated"); let _: (bool, bool) = (oh<woe, is>(me)); That is actually comparing the string "the" against the string "Turbofish" and the string "remains" against the string "undefeated". The test case is there to point out that if the "::" in the turbofish is removed (Vec<u32>::new() instead of Vec::<u32>::new()) there will be cases where it's ambiguous. [1] https://twitter.com/whoisaldeka/status/914914008225816576?lang=en https://twitter.com/whoisaldeka/status/914914008225816576?la... EDIT: Fix my misspelling of ManishEarth
- eslaught 6y agoSee also this comment that makes the ambiguity explicit: https://github.com/rust-lang/rfcs/pull/2527#issuecomment-414635205 https://github.com/rust-lang/rfcs/pull/2527#issuecomment-414...
- IainIreland 6y agoFor the record, I suspect "Manis Heath" is in fact "ManishEarth", aka Manish Goregaokar.
- iudqnolq 6y agoThank you! Fixed
- OJFord 6y agoIf it helps, for years I read 'dang' as just a fun internet alias, as in Dang son, that's embarrassing. It wasn't until that NYT (or whichever paper) interview with 'Dan G[...] HN moderator' that it clicked. (I still frequently hear it wrong in my head. Habits..)
- samatman 6y agoCaps being allowed in HN handles (if mildly deprecated for cultural reasons) we must presume this to be intentional.
- OJFord 6y agoDear Mr S. Amat MA (N), You raise a good point. I've had a few emails addressing me 'OJ' Ford, which is beyond reasonable in hindsight, just not something I foresaw or that anyone's ever called me in person! Perhaps I unwittingly contributed to that by registering my username mildly against the cultural grain.. :) Yours, O. Johnson-Fsmith Operational Research Department
- samatman 6y agoDear OJ Ford, Over the years, many have mistook my account for that of Sam Altman (sama), or presumed it to be a parody thereof. In my defense, I have been using this handle, and variants of it, for longer than he's been alive. Best, (Maha) Sam Atman "you can choose your friends but not your namesake"
- btown 6y agoOh gosh - I was so primed by the poem to see <woe, is> as a generic specifier (which I thought should fail, because "oh" isn't callable)... that I completely forgot that < is a less than operator and > is a greater than operator. This literally compiles as two string comparisons. I need to go home and rethink my life.
- steveklabnik 6y agoThe grammar conspires against your brain; when used as comparisons, we tend to include spaces around them, and as generics, we don't. But it's not required for either of those to be that way, with the whitespace. Tricky!
- zanellato19 6y agoThats exactly why it was so difficult to parse it for me for a few minutes. I do wonder, if the whitespace (or lack thereof) was mandatory, could this be resolved? What would be the impact of comparisons needing whitespace?