Live data from Hacker News

Announcing Rust 1.24.1

blog.rust-lang.org

11–20 of 66 posts

Re: Announcing Rust 1.24.1

#11
post #10

Rust gives me a headache. I want to like it, but it just seems so... overengineered https://doc.rust-lang.org/std/str/struct.SplitWhitespace.htm... Why would you create a special data type to represent a string split by Whitespace? Lunacy

That’s not a datatype... That’s an iterater returned by calling .split_whitespace() on a string. Basically the same as calling .split(‘ ‘) on a string in JavaScript You can find a list of Rusts primitive types here: https://doc.rust-lang.org/std/#primitives

> That’s not a datatype

It's a named struct. That's pretty datatype-y.

I don't agree with the GP that this is an example of overengineering. If anything it's an example of current Rust being slightly underengineered. Presumably a lot of these temporary types can be killed off once `impl Trait` goes mainstream?

Re: Announcing Rust 1.24.1

#12

Rust gives me a headache. I want to like it, but it just seems so... overengineered https://doc.rust-lang.org/std/str/struct.SplitWhitespace.htm... Why would you create a special data type to represent a string split by Whitespace? Lunacy

> Why would you create a special data type to represent a string split by Whitespace? Lunacy

Because it's an iterator. A bespoke iterator type is also created behind the scenes in many other languages. How else would you do it?

Re: Announcing Rust 1.24.1

#13
post #10

Earlier quoted context omitted.

That’s not a datatype... That’s an iterater returned by calling .split_whitespace() on a string. Basically the same as calling .split(‘ ‘) on a string in JavaScript You can find a list of Rusts primitive types here: https://doc.rust-lang.org/std/#primitives

> That’s not a datatype It's a named struct. That's pretty datatype-y. I don't agree with the GP that this is an example of overengineering. If anything it's an example of current Rust being slightly underengineered. Presumably a lot of these temporary types can be killed off once `impl Trait` goes mainstream?

I would never want the named types to go away. They heavily improve the error messages you get.

Re: Announcing Rust 1.24.1

#14

Rust gives me a headache. I want to like it, but it just seems so... overengineered https://doc.rust-lang.org/std/str/struct.SplitWhitespace.htm... Why would you create a special data type to represent a string split by Whitespace? Lunacy

As implied by other commenters, the problem is that Rust cannot currently abstract out a concrete return type without indirection of some sort. More formally, it’s not possible to existentially quantify over a trait bound; in other words, to say that whatever the actual type that is returned, all the caller needs to know is that it implements a certain trait or traits.

Note that it’s exactly the same in other major statically-typed languages like Java or C++: there are no existential types without indirection (which in the case of Java and similar managed languages is implicit and mandatory).

Rust is in the progress of adding existential trait bounds in the form of the `impl trait` feature. It’s already available in nightly.

Re: Announcing Rust 1.24.1

#15

Rust gives me a headache. I want to like it, but it just seems so... overengineered https://doc.rust-lang.org/std/str/struct.SplitWhitespace.htm... Why would you create a special data type to represent a string split by Whitespace? Lunacy

> Why would you create a special data type to represent a string split by Whitespace?

Big chunks of Rust are build around iterators, and `split_whitespace` returns an iterator of type `SplitWhitespace`. Because this is a concrete type, the Rust compiler and LLVM will then work to together to completely inline it, and they will generate code that looks like a hand-rolled loop.

There are some downsides to this system—it usually takes me about 10 minutes to write custom iterators for a new data structure—but iterators are very nice to program with and they go fast.

There's a new 'impl Trait' feature scheduled for later this year which will eliminate the need to export a custom struct like this. And it will eliminate the 10 minutes I spend writing iterators. Of course, it adds a new language feature. Nothing's free.

> Rust gives me a headache. I want to like it, but it just seems so... overengineered

I admit, Rust does sometimes have a "heavy industry" feeling to it. But this has some nice benefits, too:

1. I can write cross-platform CLI tools that Just Work on Linux, MacOS and Windows, because Rust has good abstractions for paths, files, threads, etc.

2. I can write multi-threaded code that does things like, "Read an arbitrary stream of bytes in a background thread, compress it, break it into 5MB chunks, and upload each of those chunks to S3 in parallel, using no more than N worker threads and applying backpressure, and do all this in the background while I work on something else." And thanks to Rust's threading rules, all this will work on the first try, with no nightmarish threading bugs.

3. In general, if my Rust code actually compiles, there's about an 85% chance that it will work flawlessly on the first try.

Personally, these are benefits that I'm willing to pay for. And Rust does require some familiarity both with how processors work, and with functional programming. And of course, everybody has different tradeoffs. But for certain kinds of work, Rust really hits the sweet spot.

Re: Announcing Rust 1.24.1

#16

Rust gives me a headache. I want to like it, but it just seems so... overengineered https://doc.rust-lang.org/std/str/struct.SplitWhitespace.htm... Why would you create a special data type to represent a string split by Whitespace? Lunacy

Because unlike most other programming languages, Rust is well-engineered and seeks to both provide the most general abstractions possible and to make the code generated by them as efficient as possible.

In particular, for this task, this requires to:

1. Return references to subranges of the original string, rather than copying them, so that no copy happens if you only need to examine the component instead of storing it

2. Not use reference counting to do so, but rather statically checked references with lifetimes, to avoid unnecessary instructions to update the reference count and lack of a static finalization point

3. Provide a way to get components one by one, so that if you only need e.g. the first two, time is not wasted to split the whole string

4. Provide that through a generic Iterator trait, so that it may be passed to generic methods (like one that collects the result into a vector)

5. Dispatch that generic trait statically rather than using an indirect call as that would destroy performance

6. Make the state manipulated by such an interface into a first-class object, and allow to put them in a data structure (like an array) while still doing static dispatch, so that you can, for instance, split multiple strings into components and interleave them without ever making an indirect call.

The combination of these essential requirements results in the creation of the SplitWhitespace data type, which represents the state of a parser splitting a string into 'a-lifetime references to whitespace-separated its components one by one, implementing the Iterator trait, and usable in a data structure.

Re: Announcing Rust 1.24.1

#17
post #14

Rust gives me a headache. I want to like it, but it just seems so... overengineered https://doc.rust-lang.org/std/str/struct.SplitWhitespace.htm... Why would you create a special data type to represent a string split by Whitespace? Lunacy

As implied by other commenters, the problem is that Rust cannot currently abstract out a concrete return type without indirection of some sort. More formally, it’s not possible to existentially quantify over a trait bound; in other words, to say that whatever the actual type that is returned, all the caller needs to know is that it implements a certain trait or traits. Note that it’s exactly the same in other major s…

> Note that it’s exactly the same in other major statically-typed languages like Java or C++

It's not just statically typed languages. Python also returns loads of special types from iterator functions, they are just usually not documented as being types:

    >>> type(itertools.chain([1, 2], [3, 4]))
    

Re: Announcing Rust 1.24.1

#18
post #14

Earlier quoted context omitted.

As implied by other commenters, the problem is that Rust cannot currently abstract out a concrete return type without indirection of some sort. More formally, it’s not possible to existentially quantify over a trait bound; in other words, to say that whatever the actual type that is returned, all the caller needs to know is that it implements a certain trait or traits. Note that it’s exactly the same in other major s…

> Note that it’s exactly the same in other major statically-typed languages like Java or C++ It's not just statically typed languages. Python also returns loads of special types from iterator functions, they are just usually not documented as being types: >>> type(itertools.chain([1, 2], [3, 4]))

Yes, I just meant that in a dynamically typed language you don’t have the problem of types leaking to signatures because there are no type annotations in the first place. And when there are, everything has indirection anyway.

Re: Announcing Rust 1.24.1

#19
post #15

Rust gives me a headache. I want to like it, but it just seems so... overengineered https://doc.rust-lang.org/std/str/struct.SplitWhitespace.htm... Why would you create a special data type to represent a string split by Whitespace? Lunacy

> Why would you create a special data type to represent a string split by Whitespace? Big chunks of Rust are build around iterators, and `split_whitespace` returns an iterator of type `SplitWhitespace`. Because this is a concrete type, the Rust compiler and LLVM will then work to together to completely inline it, and they will generate code that looks like a hand-rolled loop. There are some downsides to this system—i…

>and upload each of those chunks to S3 in parallel, using no more than N worker threads

Do you use a crate like Rayon for this? I'm just starting with Rust, and my current understanding is that without using a library, one can only spawn threads and distribute load by hand (as opposed to automatic scheduling a-la OpenMP). Is this correct?

Re: Announcing Rust 1.24.1

#20
post #6

> Cargo couldn’t fetch the index from crates.io if you were using an older Windows without having applied security fixes. Why are developers (since this is an issue that shows up with cargo) running Windows 7 without security patches installed? Especially since the issue only shows up on Windows 7 installs that haven't received security patches since June 2016. > libgit2 created a fix, using the WinHTTP API to reques…

> Why are developers (since this is an issue that shows up with cargo) running Windows 7 without security patches installed? Especially since the issue only shows up on Windows 7 installs that haven't received security patches since June 2016.

Enterprise. It’s only recently I’ve stopped seeing XP boxes around, but Windows 7 is everywhere.

Post reply on HN