Most active commenters
  • estebank(3)

←back to thread

177 points signa11 | 11 comments | | HN request time: 2.04s | source | bottom
1. amelius ◴[] No.42160877[source]
Yes, and people should stop using Rust for projects that do not require a systems programming language.

Know what tool to pick.

replies(4): >>42160896 #>>42160922 #>>42161000 #>>42163093 #
2. kstrauser ◴[] No.42160896[source]
I used it for an API server and it was pleasantly fun. “Systems” is a broad brush.
3. eYrKEC2 ◴[] No.42160922[source]
It's a high level language with algebraic data types and fantastic type checking. I'll use it where ever I darn well please.
replies(1): >>42160951 #
4. runeblaze ◴[] No.42160951[source]
Sometimes I write Rust with Arc and Rc sprinkled everywhere because I just need a dialect of OCaml.
replies(1): >>42161177 #
5. maxbond ◴[] No.42161000[source]
Sure. But pick based on concrete knowledge of the tool rather than broad and abstract categories. Tools are routinely discovered to be more broadly applicable than their initially intended use case, or even to be poor fit for that use case. The map is not the terrain.

And in any case, ecosystem usually trumps other concerns. Deep learning is a task you'd think a system language would be ideal for. Yet Python is a probably a better choice than Rust. The best reason to avoid Rust for a new project is probably that the market for Rust developers is insufficiently liquid (though presumably that won't be true for much longer, if it's still true at all).

6. estebank ◴[] No.42161177{3}[source]
The only thing that's really missing is deref patterns so that you can pattern match on an Arc<T> with a T pattern.
replies(1): >>42165742 #
7. goku12 ◴[] No.42163093[source]
People conflate difficulty of Rust borrow checker with the inherent difficulty in systems programming. However, this is not true. Both C and C++ are primarily systems programming languages. However, that never dissuaded anyone from using them as general purpose programming languages. The same should apply to Rust as well.

Meanwhile, Rust is my programming language and I choose it unless there is a good reason to choose another language. I never really struggled with the borrow checker. I think a lot of beginners approach the BC wrongly. Trying to memorize the rule is definitely the wrong way.

8. goku12 ◴[] No.42165742{4}[source]
Shouldn't this be possible already? Deref is implemented for Arc<T>.

[1] https://doc.rust-lang.org/std/sync/struct.Arc.html#impl-Dere...

[2] https://rust-lang.github.io/rfcs/2005-match-ergonomics.html

replies(1): >>42166761 #
9. estebank ◴[] No.42166761{5}[source]
I mean having the following work:

  match Arc::new("hello") {
      "hi" => {}
      "hello" => {}
      _ => {}
  }
It is an extension of match ergonomics, called deref patterns. There's some experimental code to make it work for `String` to `&str` (`if let "hi" = String::from("hi") {}`), but it is not anywhere close to finished. The final version will likely have something like a `trait DerefPure: Deref {}` signaling trait. There is disagreement on whether giving users the possibility to execute non-idempotent, non-cheap behavior on `Deref` and allow them to `impl DerefPure` for those types would be a big enough foot-gun to restrict this only to std or not.
replies(1): >>42167408 #
10. sfink ◴[] No.42167408{6}[source]
What's the difference and advantage, other than less typing, of this over:

     match *Arc::new("hello").as_ref() {
      "hi" => {}
      "hello" => {}
      _ => {}
(Sorry, Rust newbie here)
replies(1): >>42168568 #
11. estebank ◴[] No.42168568{7}[source]
Patterns can be arbitrarily complex. If you have

  struct Foo {
      bar: Arc<String>,
  }
Then it's the difference between today's

  if let Foo { bar } = val {
      if &*bar == "hi" {
      }
  }
And the potential future

  if let Foo { bar: "hi" } = val {}
The more complex the pattern, the bigger the conciseness win and levels of nesting you can remove. This comes up more often for me with `Box`, in the context of AST nodes, but because I use nightly I can use `box` patterns, which is the same feature but only for `Box` and that will never be stabilized.