Follow

Just had my first occasion to use 's turbofish syntax, in the enjoyably concise/cryptic line `(0..=n).sum::<u32>().pow(2)`

Related: this is pretty great in case you haven't seen it: turbo.fish/

@codesections Honestly more surprised you ran into ..= syntax faster! Did you get it from clippy or just learn it from elsewhere?

@Eden I think I came across the `..=` syntax in a discussion of whether `0..=n` is as fast as `0..n + 1` (tl;dr;, no because it makes a couple extra checks regarding overflow that result in extra assembly instructions).

My one biggest complaint with the Rust book, by the way, is that it makes it surprisingly easy to miss little bits of syntax like this—but maybe that's just from comparing Rust to languages that don't *have* as much syntax.

@codesections That is really interesting.

Yeah! I missed loads from the rust book - big ones being how to use where for generics. Originally I saw where as restrictive, and now I see it as hugely powerful.

Do definitely play with clippy though - it's in rustup as a component, and it'll catch things like ..(n+1) and offer better syntax

@codesections @Eden .. vs ..= stood out pretty clearly to me when I read the book. It's right there in the first section about slices: doc.rust-lang.org/book/ch04-03

Coming from Python I'm all about slices and range operators though, so I tend to focus on those aspects of any new language I try.

@kungtotte @codesections Oh wow, it's fairly blatant there. I totally skimmed over it.

@codesections Oh I shouldn't have gone into the history of the turbofish syntax, the guy using it for the first time has cancer and now I'm sad

Sign in to participate in the conversation
Fosstodon

Fosstodon is a Mastodon instance that is open to anyone who is interested in technology; particularly free & open source software.