3 ms·
>I love Rust. I wish they would spend more time making it actually work for non hello-world use-cases. Considering Rust has been used for anything, from basic
by coldtea 4y ago
>I love Rust. I wish they would spend more time making it actually work for non hello-world use-cases.
Considering Rust has been used for anything, from basic userland utilities and databases, to high performance network stacks serving billions, compilers, and even Linux kernel drivers, I'd call this statement "not even wrong".
>What's the point of having the 'pretty' syntax if it only works in the simplest of cases?
That the "simplest of cases" are 90% of what you use 'for' for? The syntax should "make simple things easy, and hard things possible", and this is an example of exactly that!
>I hate syntax that only works in hello world examples
In which universe is basic iteration a "hello world" use case? It's used in basically EVERY program, all the time. That's "bread and butter", not "hello world" level.
And the rest also has a reason to be there, not that someone "infuriated" would try to go deeper.
>There should be one-- and preferably only one --obvious way to do it.
That's a design goal for another language. Which failed much worse than Rust at that, and for no good reason.
- timerol 4y agohttps://without.boats/blog/the-registers-of-rust/ https://without.boats/blog/the-registers-of-rust/ is pretty transparent about Rust not having or aiming for "only one obvious way to do it". Rust has more of a mindset that if you're willing to mess with the fiddly bits, then you get control of all of the effects.
- marcosdumay 4y ago> That the "simplest of cases" are 90% of what you use 'for' for? Anything that can't be done gets exactly 0% of the usage. I don't know where you got 90% from. The author clearly comes from a mindset of trying to write Haskell code in Rust. But the criticism is fair, those are 3 very ugly aspects of the language, and it may be possible to improve them without breaking the general behavior... And even if it isn't, it is well worth it to be aware of them.
- coldtea 4y ago>Anything that can't be done gets exactly 0% of the usage. I don't know where you got 90% from. I'm not sure what the first sentence means. Plain iteration across all elements is the most common case for "for". That's where I get the 90% from (meaning, most of the time you'll be doing that). for/in without filters etc., is not something that's just for "hello world" style programs (only useful as a very crude example that you wont find in any real program) - as the author describes it. It's the very opposite: what you will most commony use in every program you write multiple times.
- drewcoo 4y agoTaking everything someone says strictly literally does not make other people "not even wrong." It's a reading comprehension error and is uncharitable. The author really likes Rust. He's not some naysayer. He'd just like Rust to be even better. He provides constructive feedback.
- coldtea 4y ago>Taking everything someone says strictly literally The author intents it to be taken literally. He even goes on to expand on the "literalliness" of his put-downs, with several paragraphs of invalid arguments furthering the exaxt same non-point. >The author really likes Rust. Liking and understanding are too different things. >He provides constructive feedback. See, this is where I beg to differ.
- lcnPylGDnU4H9OF 4y agoI'm not familiar with Rust. for x in &mut something { *x = (*x) * 2; } Here (above) it looks like the `&mut` is allowing the iterator to be mutable (https://doc.rust-lang.org/std/keyword.mut.html https://doc.rust-lang.org/std/keyword.mut.html). for (i, x) in something.iter_mut().filter(|| {...}).enumerate() { *x = (*x) * i } The `mut` keyword isn't needed here because, I assume if the above assumption is correct, "iter_mut()" is returning a mutable iterator. Is there some reason the result of "something.iter_mut().filter(|| {...}).enumerate()" can't be saved to a variable and then used as the "something" in the first example? Anyway, this post reminds me of an article, "Why Programming Language X is Unambiguously Better Than Programming Language Y"[0]. Mostly talking about how [poorly written Y code] is why Y is a bad language and [beautiful and elegant X code] is why X is a good language. [0] https://news.ycombinator.com/item?id=6960398 https://news.ycombinator.com/item?id=6960398; unfortunately the link is dead and I can't find it on the domain
- thethirdone 4y ago> Is there some reason the result of "something.iter_mut().filter(|| {...}).enumerate()" can't be saved to a variable and then used as the "something" in the first example? You absolutely can do something like `let iter = something.iter_mut().filter(|| {...}).enumerate();` In Rust, Iterators are just need to implement a Trait (kindof like an Go or Java interface) so they can be put in normal variables just fine. > The `mut` keyword isn't needed here because, I assume if the above assumption is correct, "iter_mut()" is returning a mutable iterator. Every for loop implicitly calls `.into_iter()` on the thing to loop over; the docs are decent at explaining what IntoIter is [0]. By doing `&mut something` instead of just `something` you get a different IntoIter implementation which has very different semantics. Typically `(&mut something).into_iter()` would have the same behavior and might even result in the same type as `something.iter_mut()`. [0]: https://doc.rust-lang.org/std/iter/trait.IntoIterator.html https://doc.rust-lang.org/std/iter/trait.IntoIterator.html
- lcnPylGDnU4H9OF 4y agoThanks for taking the time to explain!