News for hackers. Stuff that matters.
Re:Thoughts on Rust, a few thousand lines in by Retra on Wednesday January 09, 2019 @06:42PM (#18870185)
Panics are not unsafe. Panic exists in Rust because they are safe. If you don't want a panic on index, just don't index.

Indexing into a UTF-8 string doesn't serve any reasonable consistent purpose anyway, because it is an abstraction of text that doesn't provide support to the notion that a "character" is more fundamental than a word or paragraph, etc. Rust's string slicing exists solely to make ASCII text easy to handle. If your text is not ASCII, then you shouldn't be slicing it at all. Thus the panic.

Re:Thoughts on Rust, a few thousand lines in by dkarl on Thursday January 10, 2019 @01:00AM (#18871857)
Indexing into a UTF-8 string doesn't serve any reasonable consistent purpose anyway

If that's true, isn't it the job of a type system to help avoid such nonsensical operations? If "slice" only makes sense for byte arrays and ASCII strings, it could be provided on those types without being defined on UTF-8 strings.

Panics are not unsafe. Panic exists in Rust because they are safe.

That's "safe" by a very limited definition of safety. It's one step up from undefined behavior, granted, but it's not a very high standard. In practice, in most programs, you'd want to ensure that such a panic would never happen, and personally I think the language's unhelpfulness in that regard is a wart.

Re:Thoughts on Rust, a few thousand lines in by Retra on Thursday January 10, 2019 @09:34AM (#18874060)
>If that's true, isn't it the job of a type system to help avoid such nonsensical operations?

It's not strictly true, because there are situations where you want to slice UTF-8. For instance, if you already know where the code point boundaries are for newlines. But if you know that, then you've run something like a regex with >O(1) behavior and you certainly wouldn't want string slicing to do redundant work.

>hat's "safe" by a very limited definition of safety

That's the definition of safe that is used. Safety in the context of Rust means memory safety. (Division can panic, btw.) If you don't see why undefined behavior is so much worse than a panic, then do some research on it. If you want programs that never fail, you need a comprehensive plan that takes into account things like hardware failure. A programming language can't do that.

Re:Thoughts on Rust, a few thousand lines in by int_19h on Wednesday January 09, 2019 @07:28PM (#18870467)
I think that's too extreme. There are many legitimate reasons to slice non-ASCII text - for example, to split it on newlines.
Re:Thoughts on Rust, a few thousand lines in by mlindner on Wednesday January 09, 2019 @08:45PM (#18870832)
That's not trivial and different languages vary in how they handle new line characters even. https://stackoverflow.com/questions/44995851/how-do-i-check-...
Re:Thoughts on Rust, a few thousand lines in by int_19h on Wednesday January 09, 2019 @11:32PM (#18871541)
You can still split non-ASCII text on ASCII newlines, and quite often that's exactly what needs to be done.
Re:Thoughts on Rust, a few thousand lines in by Retra on Thursday January 10, 2019 @09:34AM (#18874062)
And usually, you don't want it to cost O(n) on top of whatever parser you ran to find those newlines.