News for hackers. Stuff that matters.
Re:Futures explained in 200 lines of Rust by brobinson on Thursday December 03, 2020 @01:39PM (#25292697)
I recently spent 15 minutes going over a Rust futures tutorial and was then able to get a Rust program streaming live bitcoin futures (coincidence!) over websocket connections from multiple exchanges working in less than an hour.

I then then attempted to port some Python code to use Python's new async/await and was unsuccessful. I managed to get a bunch of async workers running, but only the first one would process jobs from the queue or the entire program would just hang indefinitely. Couldn't figure it out after two hours and just gave up on it.

Nice work, Rust team. This is a game changer for me.

Re:Futures explained in 200 lines of Rust by ygram on Thursday December 03, 2020 @02:28PM (#25293391)
Python got async/await in 2015, so not exactly new.
Re:Futures explained in 200 lines of Rust by brobinson on Thursday December 03, 2020 @03:34PM (#25294398)
I still find people writing new code in Python 2 so I consider 3.7.x to be "new", but you are right.
Re:Futures explained in 200 lines of Rust by jib_flow on Thursday December 03, 2020 @02:48PM (#25293711)
As someone who has struggled learning Rust, it's incredible to me you were able to do this so quickly. Had you spent much time prior with Rust?
Re:Futures explained in 200 lines of Rust by brobinson on Thursday December 03, 2020 @03:34PM (#25294392)
I've been using it off and on since late 2014, back when my code would stop working every week due to a new breaking change. :D
Re:Futures explained in 200 lines of Rust by jib_flow on Thursday December 03, 2020 @07:19PM (#25297410)
Ah, well that makes me feel a bit better as I've only picked it up this year. Good to know it gets easier with time!
Re:Futures explained in 200 lines of Rust by brobinson on Thursday December 03, 2020 @07:59PM (#25297684)
It does get easier with time... stick with it!
Re:Futures explained in 200 lines of Rust by martamorena9182 on Thursday December 03, 2020 @03:09PM (#25294022)
Looking at the code, it's a nightmare to parse. There are so many details to deal with that should never bother you under normal circumstances (the core problem of using Rust where it's not necessary). It's admirable that you have such an easy time with it. However, for most people, using Rust for these purposes is absolutely not recommended.

Java/Kotlin paired with reactive streams makes these tasks super easy to read, once you get the hang of reactive streams. Also there are complexities in there, you just simply can't brush all the intricacies of network programming and multi-threading under the rug, but at least you are dealing only with the complexities that are necessary for your problem.

With Rust you are dealing with tons of additional complexity that doesn't matter to 99% of people & problems. I love that Rust exists and it has its uses (browsers, hypervisors, drivers, kernels, etc). I just find it very alienating when people compare this to Python and do everyday tasks with it.

No, you really don't want to deal with borrowing, memory management and life-times, unless it is part of the problem you are trying to solve (and there aren't too many for which that applies).

Re:Futures explained in 200 lines of Rust by steveklabnik on Thursday December 03, 2020 @05:41PM (#25296311)
This code is all about learning about how this stuff works at a deeper level. To use async Rust, you need to write none of this code.
Re:Futures explained in 200 lines of Rust by martamorena9182 on Friday December 04, 2020 @12:29PM (#25305149)
Yes, this is usually how it turns out in practice. You don't need to understand what's going on under the hood, you just string some libraries together and call it a day ;).

/sarcasm off

Re:Futures explained in 200 lines of Rust by steveklabnik on Friday December 04, 2020 @02:24PM (#25306533)
Abstractions and use of them is the core of our discipline, not sure why you think your comment is sarcastic.
Re:Futures explained in 200 lines of Rust by chridou on Friday December 04, 2020 @04:24AM (#25300513)
> However, for most people, using Rust for these purposes is absolutely not recommended.

Who are these "most people"? Can you get more specific here?

> Java/Kotlin paired with reactive streams makes these tasks super easy to read, once you get the hang of reactive streams. Also there are complexities in there, you just simply can't brush all the intricacies of network programming and multi-threading under the rug, but at least you are dealing only with the complexities that are necessary for your problem.

The text goes pretty much into detail. I do not understand where Rusts streams are more complicated than the Java/Kotlin/Scala ones? Did you ever write an application with reactive streams and got problems with the thread pool, people unknowingly blocking in combinators, etc..? I'd dare to say that these things also add complexity that is not necessary to the kind of problems you defined as "99% of ..."

> With Rust you are dealing with tons of additional complexity that doesn't matter to 99% of people & problems.

Where did you get that number from? What are "tons of additional complexity"?

> I just find it very alienating when people compare this to Python and do everyday tasks with it.

Maybe you just have not yet recognized that you can do everyday tasks with it?

Re:Futures explained in 200 lines of Rust by db48x on Friday December 04, 2020 @01:03AM (#25299503)
This article is explaining how Futures work by showing you what's under the covers. You don't actually have to write this code yourself, you can just use one of many wonderful libraries that handle it all for you.

As it says in the second paragraph: "Going into the level of detail I do in this book is not needed to use futures or async/await in Rust. It's for the curious out there that want to know how it all works."