Live data from Hacker News

My least favorite Rust type

ridiculousfish.com

231–240 of 298 posts

Re: My least favorite Rust type

#231

Range's idiosyncrasies and the antipathy to improving its ergonomics manifest in the issues raised against the project have been a capstone mental block to my investing emotionally in Rust. I continuously really want to like the language. The premise is good, a lot of the ideas are really compelling, but when it comes down to aspects I disagree with, I get a strong sense of Rust demanding that users subjugate themsel…

[deleted]

Re: My least favorite Rust type

#232

Earlier quoted context omitted.

Interesting: .len() is not the length of a slice induced by the range or the distance between start and end but instead it's the len method form `ExactSizedIterator`, which in turn is a "special case" of where `Iterator.size_hint()` is known to return a correct value. The thing is `Iterator.size_hint()` does return a size, which is usize. So `Range ` can only implement `ExactSizedIterator` on 64-bit targets, which I…

This is another Rust design mistake: conflating the platform pointer size with "lengths". It's possible to process files bigger than 4 GB on 32-bit platforms. It's even possible to memory map them (using sliding windows/views). In some Rust forums, the language designers were shocked to learn that this is possible. At any rate, the Range type was very clearly designed for slices of in-memory contiguous arrays. Then t…

> In some Rust forums, the language designers were shocked to learn that this is possible.

Who? Where? I guarantee you that the people responsible for the `usize` type, or its usage in the stdlib collections, were not shocked.

Re: My least favorite Rust type

#233
post #128

Earlier quoted context omitted.

It looks like you can't. You can create a Range out of it, but the range is not an iterator. If you look at the Range docs[0], you'll see that it only implements Iterator where its generic type (A) implements std::iter::Step. Going to the Step docs[1] you'll see that its only implemented by integer types and char. If Vec implemented Step, you could iterate over it. Also, if you're referring to the "contains" guessing…

That’s what I did (at repl.it anyway)... how do I print the values in a Range of Vectors?

The range doesn't have values. A range defined by Rust has a start point and an end point, and no other semantics. Some additional functions then add behavior if the types contained in the range can be compared via greater-than, etc. Vecs in Rust can be compared if their contents can be compared. For a range of two vecs, foo and bar, to ask if a third vec is "contained" in that range is to ask if it compares greater than foo and less than bar.

Re: My least favorite Rust type

#234
post #128

Earlier quoted context omitted.

It looks like you can't. You can create a Range out of it, but the range is not an iterator. If you look at the Range docs[0], you'll see that it only implements Iterator where its generic type (A) implements std::iter::Step. Going to the Step docs[1] you'll see that its only implemented by integer types and char. If Vec implemented Step, you could iterate over it. Also, if you're referring to the "contains" guessing…

That’s what I did (at repl.it anyway)... how do I print the values in a Range of Vectors?

Does debug print not work {:?}

Re: My least favorite Rust type

#235

Earlier quoted context omitted.

> The problem is that his/her proposal … Please just use the word “their”. “his/her” is not just awkward but also not even inclusive, as there are many people who do not use “his” or “her” pronouns.

It's sad how many cumulative hours have been lost to policing language just because some <1% of the population decided to treat their pronouns like a fashion accessory that must be as unique as possible.

Do you take joy in starting threads like this? You keep doing it.

Just let it go. If you don't like the comment, down vote it.

When you reply, you just create an irrelevant pointless subthread that has nothing to do with the actual post.

Yes, this applies to the parent comment too...

...but the parent comment wasn't being a dick about it.

Your comment is creating a pointless thread and being inflammatory, which is just flat out trolling.

Re: My least favorite Rust type

#236

Range's idiosyncrasies and the antipathy to improving its ergonomics manifest in the issues raised against the project have been a capstone mental block to my investing emotionally in Rust. I continuously really want to like the language. The premise is good, a lot of the ideas are really compelling, but when it comes down to aspects I disagree with, I get a strong sense of Rust demanding that users subjugate themsel…

> I get a strong sense of Rust demanding that users subjugate themselves to all the choices and opinions of the architects

I don't know why you feel that way. Any major language or standard library change goes through an RFC process, where anyone in the community can submit feedback, and from what I have seen, the official teams are very responsive to concerns.

Re: My least favorite Rust type

#237
post #121

Earlier quoted context omitted.

There are plenty of hurdles in Rust, but I wouldn't call this one of them. What exactly do you expect an Iterator for a range of vectors to do?

Traverse the entries?

we're talking about a range of vec![8,9]..vec![1,2] for example. What does 'traverse the entries' between those two values mean?

Re: My least favorite Rust type

#238
post #121

Earlier quoted context omitted.

There are plenty of hurdles in Rust, but I wouldn't call this one of them. What exactly do you expect an Iterator for a range of vectors to do?

Not really a Rust programmer, but I would expect a Range of vectors to operate something like a vector of Ranges. So if you say [0,10]..[20, 30], the length would be twenty, and the elements would be [1,11], [2,12]... Presumably if there was asymmetry in the values like [1,10]..[20, 50] you'd end up with...something? Not really sure what it should be, there are lots of options!

The fact that there are options is my point: it's ambiguous. That's the reason there is no implementation for it in the std lib. You're absolutely free in Rust to define your own though.

Re: My least favorite Rust type

#239

Earlier quoted context omitted.

Most of the methods are constrained to types that implement PartialOrd.

Yes, but why does Rust's Range type not require this?

As others have said you don't often put constraints on types in struct definitions. Most of the time if you do it is for using associated types to simplify generics.

The reason why constraints on structs isn't a good API design is because it limits future API design scope unnecessarily. In this case, maybe you want to reuse the Range syntax as part of a DSL?

Re: My least favorite Rust type

#240
post #209

Earlier quoted context omitted.

I was super excited about the idea of Rust but constantly frustrated trying to use it to write real code. I've basically decided to stay in my (ever-improving) comfort zone of C++ until Rust gets named/default arguments, which is my arbitrary litmus test for whether it's going to actually be a usable language for me.

You can do that now. Its not quite the same but pretty close: fn f(n: Option ) -> u8 { match n { Some(n0) => n0, None => 10 } } fn main() { let n1 = f(Some(20)); let n2 = f(None); println!("{} {}", n1, n2); }

You're missing the point. Here's a good article that talks about the problems of having neither overloading nor default parameters, but in Go.[1] The problem is made significantly worse in Rust when all struct fields need to be initialized and there are no varargs. I really see no solution to the "stable API with more options" problem in Rust, aside from a builder pattern, which I really hate.

1: https://dave.cheney.net/2014/10/17/functional-options-for-fr...

Post reply on HN