News for hackers. Stuff that matters.
Re:Thoughts on Rust, a few thousand lines in by ilovecaching on Wednesday January 09, 2019 @04:52PM (#18869317)
I'm a network engineer, and I've done C++ for over a decade now. One of the nice things about Rust is that they decided to go with async over fibers, which is in line with how most high performance C++ is written. The Rust team also isn't rushing Future out the door, so it's coming along much nicer than the C++ Future, which is usually replaced because it's not monadic.

Rust is great, and I highly recommend learning Rust if you want to become a better C++ developer. C++ introduces a lot of unnecessary headaches Rust completely solves. Rust is worth the switch if only because reading error messages from expanded templates is horrible compared to type system that actually understands type parameters.

I'm really bullish on Rust becoming even more mainstream, to the point anyone can pick it up and use it in their business without a second thought by 2020.

Re:Thoughts on Rust, a few thousand lines in by skyde on Wednesday January 09, 2019 @10:19PM (#18871239)
I am a big fan of rust but I don’t think the Async using the ”await” keyword or using Future/promis is the way to go.

I wrote a large web app in scala using Futur only and it turned into a monster because of it. Even if you don’t use callback you still need to manualy unwrap them and they pollute your méthode signature.

Then more recently I wrote a pub/sub server in c# using the “await” keyword. While much better it still polute your method signature and make the debugger and stacktrace useless. Also you still have to think about trying to no make anything that could block spinlock or calling api that are not Async ex: Createfile

Compare this to Golang where project like Groupcache (1) have super clean code that replaced a thousand line of code C++ system at google.

Why do you think Golang fiber/gorotine are worse ?

(1) https://github.com/golang/groupcache

Re:Thoughts on Rust, a few thousand lines in by ilovecaching on Wednesday January 09, 2019 @11:12PM (#18871468)
The answer to this question is quite involved. As you may already know, Rust at one time had a fiber model, but it was removed in favor of Futures.

One big advantage of Futures is they are decoupled from their execution environment.

For example, different types of executors can be used depending on the type of Future. For example, you may have an IOThreadPoolExecutor to handle accepting and responding to connections that should spend very little time blocking and a CPUThreadPoolExecutor for offloading heavy processing. In Go, you have no say in how goroutines are scheduled, you sacrifice control to reduce complexity.

Another big one in network programming is the polling mechanism. In Go, you have no control over your polling mechanism, whereas with a Future is decoupled from the event loop, and you can write your own event loop on any experimental kernel APIs you'd like.

Rust made the right move because in Rust, just as in C++, we want maximum control. Futures are more primitive, and it's possible to build coroutine models on top of them, but not vice versa.

Re:Thoughts on Rust, a few thousand lines in by skyde on Thursday January 10, 2019 @11:37AM (#18875178)
I agree with you. I guess the best solution would be something in between “await” and goroutine.

My understanding is the main issue with “await” model is that you only abstract The Task model.

Running task don’t gave a real ID and stack like “Go” and “Erlang” you can list all running fiber how much memory and CPU they use ...

I believe you could write your own event loop easily in Go if they exposed the internal api used to pause and resume goroutine, you can already pause goroutine by having them wait on a mutex and resume them from your custom event loop by releasing that mutex.

Re:Thoughts on Rust, a few thousand lines in by cpuguy83 on Thursday January 10, 2019 @12:40AM (#18871778)
In go toh can't control the polling mechanism if you are using the Builtin types.

You can drop to raw fd's and do whatever you like... of course this negates a lot of the niceties that go affords you.

Re:Thoughts on Rust, a few thousand lines in by eptcyka on Thursday January 10, 2019 @01:20PM (#18876402)
> Rust at one time had a fiber model, but it was removed in favor of Futures.

No, fibers were removed with nothing to replace them. The futures as we know them today did not exist in the far, far past when fibers and the whole runtime thing got dropped.

Re:Thoughts on Rust, a few thousand lines in by apta on Thursday January 10, 2019 @09:17PM (#18880495)
Futures and fibers are not mutually exclusive, as shown in the latest (2018) Oracle Code One keynote speech, where they demoed project Loom (basically you can wrap a fiber in a CompletableFuture, in the same fashion you can wrap a thread/execution context and expose it in a CompletableFuture). That being said, the JVM team seem to have come to a similar conclusion that using fibers is the least invasive way in terms of syntax as compared to async.
Re:Thoughts on Rust, a few thousand lines in by pcwalton on Wednesday January 09, 2019 @10:31PM (#18871285)
Goroutines are just threads, with a particularly idiosyncratic implementation. You can use threads and blocking I/O in Rust too.

You wouldn't want a Go-like M:N solution in Rust. It would be slower for no reason.

Re:Thoughts on Rust, a few thousand lines in by comex on Wednesday January 09, 2019 @10:43PM (#18871329)
> You wouldn't want a Go-like M:N solution in Rust. It would be slower for no reason.

Depends on how many threads you have and what OS you’re running on.

Re:Thoughts on Rust, a few thousand lines in by skyde on Thursday January 10, 2019 @11:57AM (#18875426)
Goroutine are very different from thread in practice.

you don’t have to pay the memory usage and context switch cost you would have if using large amounts of threads.

It’s also faster to do IO processing from a single thread in batch instead of having one OS thread per request.

Re:Thoughts on Rust, a few thousand lines in by pcwalton on Thursday January 10, 2019 @12:23PM (#18875740)
Context switches on I/O are the same for 1:1 and M:N because you're eating the cost of a kernel to user context switch either way.

Memory usage per thread is a property of the GC, not M:N threading. You can have very small stacks in a 1:1 implementation too.

Re:Thoughts on Rust, a few thousand lines in by skyde on Monday January 14, 2019 @02:27PM (#18905646)
there is less context switches because you cant write some data to several distinct file descriptor using a single system call.

You can also read data from several file descriptor in a single System Call.

This way you significantly reduce the number of System call instead of doing one blocking read() per connection. I believe context switch round trip (from user space to kernel to user space) is much more expensive than simply switching between goroutine of the same process.

Re:Thoughts on Rust, a few thousand lines in by nicoburns on Thursday January 10, 2019 @04:28AM (#18872608)
> and make the debugger and stacktrace useless

Chrome manages to do async stack traces for their implementation of the similar JavaScript feature. I wonder if this would be possible for C# and Rust.

[dead]
Re:Thoughts on Rust, a few thousand lines in by daboross on Wednesday January 09, 2019 @06:52PM (#18870256)
Could you site this?

I've looked at ilovecaching's comment history (at least up to ~60 days ago) and they seem consistent on being a networking programmer who uses C++. Was there a particular comment you found which would indicate this isn't the truth?

Re:Thoughts on Rust, a few thousand lines in by f2f on Wednesday January 09, 2019 @07:30PM (#18870477)
nb: you mean "cite".

why would you make me do this? you can doxx people on your own dime... still, for posterity:

https://news.ycombinator.com/item?id=18328964 "...now I am working full time as a Rust developer"

https://news.ycombinator.com/item?id=18310666 "As a long time Erlang developer..."

https://news.ycombinator.com/item?id=18265199 "As someone who has worked two jobs now writing, deploying, and operating Erlang clusters, I recommend switching to Rust."

https://news.ycombinator.com/item?id=18251478 "Becoming a professional Haskell and Erlang developer really shifted my view on OOP"

https://news.ycombinator.com/item?id=18185795 "I've been using Rust in production for a little over half a year, and my team and I have run into very few issues. [...] We're all extremely glad we chucked C++ and Go and switched to Rust. "

https://news.ycombinator.com/item?id=18171917 "I am exclusively using Go and Rust at home and at work, and I find myself equally productive in both."

you get the point.

Re:Thoughts on Rust, a few thousand lines in by moosingin3space on Wednesday January 09, 2019 @07:53PM (#18870588)
It really isn't that ridiculous that someone who has worked as a network engineer for a decade would use Erlang, C++, and Go. Even Haskell isn't too much of a stretch, considering the user's company has functional programming expertise in Erlang. Rust is a neat language that, depending on their workload, could replace all of those languages. Why the presumption of bad faith?
Re:Thoughts on Rust, a few thousand lines in by TheCoelacanth on Wednesday January 09, 2019 @08:01PM (#18870626)
Not seeing any major inconsistencies. Three months ago they exclusively used Go and Rust, at some point before that they used Erlang and Haskell and they used C++ for a total of over 10 years.
Re:Thoughts on Rust, a few thousand lines in by atombender on Wednesday January 09, 2019 @11:28PM (#18871524)
Talk about cherry-picking. It's pretty clear from those comments that they've worked with Erlang before, as well as Haskell and C++, and that they've transitioned to use Rust.

For example, in the same comment that begins with "As a long time Erlang developer", they later continue: "I’m more optimistic about Rust ... We’ve been able to scale Rust to handle the same load as our Erlang cluster". So there's no contradiction here.

Re:Thoughts on Rust, a few thousand lines in by faitswulff on Wednesday January 09, 2019 @07:52PM (#18870582)
A couple languages doesn't seem beyond the realm of possibility for one engineer to be familiar with, though?
Re:Thoughts on Rust, a few thousand lines in by siegfried-en on Wednesday January 09, 2019 @07:49PM (#18870563)
You have a point, but he never said he programmed exclusively in C++, so I don’t really see the issue here...
Re:Thoughts on Rust, a few thousand lines in by mquander on Wednesday January 09, 2019 @09:22PM (#18870999)
I guess I'm glad that someone sits around looking through comment histories skeptically, but I don't see what about these comments seem suspicious to you.
Re:Thoughts on Rust, a few thousand lines in by fxfan on Wednesday January 09, 2019 @09:44PM (#18871100)
I think what you're posting definitely sounds suspicious and a lot of rust users are doing it for the hype but.

1) rust genuinely is a great language and his opinion in the comment is something I have as a professional c++ programmer or the past

2) his comment history is only suspicious and only mildly, there's nothing outright contradictory. I would give him the benefit of doubt.