Live data from Hacker News

My least favorite Rust type

ridiculousfish.com

131–140 of 298 posts

Re: My least favorite Rust type

#131
post #3

I'm only just learning Rust so I don't know much about Rust development, but what are the chances that any of the suggestions listed at the end make it into the language?

Pretty much zero. All his points are 100% valid, but they're probably annoyances that we can live with, and Range is a really core type - changing it would break basically all Rust code in existence.

Re: My least favorite Rust type

#133
post #30
post #6

I feel like this is an example of what Jonathan Blow calls a "Big Idea" or a "100% solution". His thesis is that when you make a feature of a language too abstract and usable in many different contexts, eventually there will be so many corner cases that the result will almost certainly be clunky and full of footguns. He claims that language designers should aim for "80% solutions" instead, which cover most common usa…

Now that I know the details of Rust's range type it is extremely weird. The constraints need to be separate types. Why should range be so general as to support things that are obviously not ranges, only to return values indicating the range is malformed?

> The constraints need to be separate types. Why should range be so general as to support things that are obviously not ranges, only to return values indicating the range is malformed?

I'm not sure what malformed return values this is referring to, because I can't think of any. Is it referring to the fact that ranges where the start is greater than the end will result in an empty range? Without dependent types, which Rust doesn't have, there's no way to detect that; even in the subset of cases where the range bounds are computable at compile-time, back at 1.0 Rust didn't have the compile-time evaluation machinery necessary to make that happen. You could instead choose to interpret that a range where the start is greater than the end indicates a descending range, but plenty of other people will regard that behavior as a flaw.

Re: My least favorite Rust type

#134
post #6

I feel like this is an example of what Jonathan Blow calls a "Big Idea" or a "100% solution". His thesis is that when you make a feature of a language too abstract and usable in many different contexts, eventually there will be so many corner cases that the result will almost certainly be clunky and full of footguns. He claims that language designers should aim for "80% solutions" instead, which cover most common usa…

Reminds me of D at times. It has many fancy features and powerful metaprogramming. But it also comes with drawbacks, many simple language improvement proposals are being shot down because they break in presence of some advanced usage of those features.

But that kinda isn't the case here.

`Range` was discussed a lot before being stabilized and it's drawbacks where well known when it was stabilized.

The reason it was stabilized that way anyway was because it happens to work out best for the most common use-cases.

It's more of a "practically use-full but theoretically imperfect compromiss" thing.

The main usage of range are:

1. To iterate over it

2. To slice things using it

Which is what it is focused on in it's design.

Sure ranges could be `Copy` but one of their main purposes is to be an iterator so it's reasonable to not make them copy as that would be a usability nightmare.

Sure it's strange that you can construct a invalid range and then panic when you use it to slice something. But the alternative would be to make the creation of range fallible which is a usability nightmare. Furthermore validity depends on what you use it one, so a backwards range might be a very reasonable thing for some use-cases so practically it's best to make every `Range` valid, but not necessary every usage of one.

Sure exclusive ranges based on start+end can't contain the maximal value but that's a fundamental property of exclusive ranges defined through start+end. There is a reason mathematics have 4 kind's of ranges (differing in exclusiveness in start/stop).

Sure `.contains` takes a reference, but that's a problem about how rust can't specialize traits in how they need references for Copy methods. Not having that would prevent the usage of ranges of `BigNums` or similar reasonable usages.

Sure `RangeInclusive` could be made shorter but that also means you can't have empty inclusive ranges and you can't use it directly as an iterator, which is probably the most common use case of inclusive ranges.

All in all the `Range` types are a compromise optimized for it's most common use cases. That makes some parts sub-optimal if used for other cases but you can also always use your own types so that's not really a problem in practice.

Also he does some mistakes:

- You can't enforce `start The last point also sadly means that for certain arithmetic high performance tasks it can make sense to not use the rust provided range type but a custom one.

Re: My least favorite Rust type

#135

Earlier quoted context omitted.

Maybe he has different standards than you? I assume Jai will be similar to his games as far as attention to details goes. I would describe his games as having a maniacal attention to detail.

Then maybe he should handle Jai like he handles his games. Don't talk about it until it's almost ready to go.

...Except that he did talk about all of his games almost from the get go? He showed earliest prototypes of Braid and Witness publicaly when the games were just blocky protypes, in the latter case good 7 years before the game came out. I don't know where you got this idea from, the way he is handling the development of the language seems to be pretty much an extension of how he develops his games.

Re: My least favorite Rust type

#136

Quoted post unavailable.

I don't know anything about Johnathan Blow, so could you explain why you have a hard time taking him seriously about PL design?

I wasn't familiar with him and found this video where he seems to say a lot of things that are kind of sketchy about concurrent programming at the very start of the video: https://youtu.be/hjvtzriNlMU

Re: My least favorite Rust type

#137

> This is abusing the borrow checker as a bad linter. Range undermines the story of lifetimes and ownership, making the borrow checker feel arbitrary. This is the key part. You really shouldn't try to "censor" the math to "help" users. It just causes more pain. I'm recently been annoyed with the push back against "DynSized" again, which IMO is a symptom of the same thing. "DynSized" is the natural way to generalize R…

Are you sure about this? I've heard the quote applied specifically in the context of RAII, where he complained that there is no such thing as a generalized "resource", and that the same mechanism for handling memory access should not be used for file handles and texture maps. I don't have a link right now, but I'm pretty sure it was in his first "ideas for a programming language for games" video back in 2014. Seems to me like this range situation would be fairly analogous to that.

Re: My least favorite Rust type

#138
post #41

I broadly agree with this, and am most frequently confused by the fact that a `Range ` isn't `Copy` even if `T: Copy`. I feel this was a small design mistake (having `Range` itself be an interator instead of implementing the `IntoIterator` trait) but there is a proposal to fix this that looks like it wouldn't be breaking, and so should be possible: https://github.com/rust-lang/rfcs/issues/2848

Yeah, this sounds like it could be fixed with a one-liner without any breaking changes: `impl Copy for Range where T: Copy {}`.

That being said, I can understand why this might not necessarily be desirable for some people; Copy is generally reserved for types that are "small enough" that implicitly copying the bytes will be cheap enough to ignore. It might seem obvious that a struct containing two types that are Copy should also be cheap enough to be Copy, the line has to be drawn _somewhere_, and for any number of bytes that is chosen to be the threshold where the cost is too high, it's pretty easy to pick a size that's below that threshold but a struct containing two instances of that size is above the threshold. Because of the unclear boundaries for that sort of thing, I generally tend only to derive Copy on things in my code that thin wrappers around existing types that are Copy, e.g. `struct Foo(i32)`.

Re: My least favorite Rust type

#139

I can’t even figure out how to iterate over a Range of Vectors? iter and collect both don’t exist... Google doesn’t seem helpful either. I don’t know any rust but it seems unforgiving at the first hurdle here :-)

PartialOrd for Vec is a lexicographic ordering. Any range with more than one element will have an infinite number of elements in it.

Re: My least favorite Rust type

#140

Quoted post unavailable.

You started a flamewar and fueled it with 35 comments. That's beyond the pale. In fact, it makes me wonder what the record is for a single user in a flamewar on HN.

Can you please not do this again? I appreciate https://news.ycombinator.com/item?id=24548161, but vandalism is not a good way to pass the time. Not arson either.

You did the same thing in other threads today too (e.g. https://news.ycombinator.com/item?id=24544124). We ban accounts that do this, or at a minimum rate limit them. I'm not going to do those things right now, but if you do it again we'll have to.

We detached this subthread from https://news.ycombinator.com/item?id=24547322.

Post reply on HN