Live data from Hacker News

Thoughts on Rust, a few thousand lines in

rcoh.me

1–10 of 183 posts

Re: Thoughts on Rust, a few thousand lines in

#2
> the escape hatch suggested on the internet, `partial_cmp(...).unwrap_or(Ordering::Less)`

This is often a Bad Idea, as you get unstable sorts and you are right back to the same problem.

- Explanation: How do I get the minimum or maximum value of an iterator containing floating point numbers? — https://stackoverflow.com/a/50308360/155423

- Example: https://play.integer32.com/?version=stable&mode=debug&editio...

See also:

- How to do a binary search on a Vec of floats? — https://stackoverflow.com/q/28247990/155423

Instead, use a wrapper type or raise a panic.

Re: Thoughts on Rust, a few thousand lines in

#5

> Unlike nearly every language I’ve ever used, Rust actually encourages variable shadowing. Haskell does it too, for the same reason/purpose / with the same effect.

Swift does, but typically for Optional promotion. You see stuff like `guard let delegate = delegate else { return }` inside functions all the time, shadowing a property with a local & promoting the type from Optional to T.

It's not the same as the Rust example because you're shadowing an ivar to a local, but since `self.` is implicit you're still shadowing.

Re: Thoughts on Rust, a few thousand lines in

#7

> Unlike nearly every language I’ve ever used, Rust actually encourages variable shadowing. Haskell does it too, for the same reason/purpose / with the same effect.

Swift does, but typically for Optional promotion. You see stuff like `guard let delegate = delegate else { return }` inside functions all the time, shadowing a property with a local & promoting the type from Optional to T. It's not the same as the Rust example because you're shadowing an ivar to a local, but since `self.` is implicit you're still shadowing.

> for Optional promotion

You'll see the same in Rust

    fn example(name: Option) -> Option {
        let name = name?;
        Some(name.len())
    }
Or

    fn example(name: Option) {
        if let Some(name) = name {
            println!("{}", name.len());
        }
    }
A main difference is the requirement to use `Some`, which allows for the flexibility to apply to any enum.

> but since `self.` is implicit

To make sure I'm following, do you mean that Rust's `self.` is implicit in Swift?

Re: Thoughts on Rust, a few thousand lines in

#8

Earlier quoted context omitted.

Swift does, but typically for Optional promotion. You see stuff like `guard let delegate = delegate else { return }` inside functions all the time, shadowing a property with a local & promoting the type from Optional to T. It's not the same as the Rust example because you're shadowing an ivar to a local, but since `self.` is implicit you're still shadowing.

> for Optional promotion You'll see the same in Rust fn example(name: Option ) -> Option { let name = name?; Some(name.len()) } Or fn example(name: Option ) { if let Some(name) = name { println!("{}", name.len()); } } A main difference is the requirement to use `Some`, which allows for the flexibility to apply to any enum. > but since `self.` is implicit To make sure I'm following, do you mean that Rust's `self.` is…

Yeah `self.` is implicit. In Swift:

  struct S {
    var string: String
    func doSomething() {
      // These two lines are equivalent.
      print(string)
      print(self.string)
    }
  }
Post reply on HN