News for hackers. Stuff that matters.
Re:Operating System Development in Rust by krenoten on Sunday January 11, 2015 @04:23PM (#8871375)
Many people seem to be confused by Rust's lack of limitations imposed on you as a programmer. In particular, the fact that so much of what is thought of as a runtime is provided as optional libraries. You can run tasks similar to Goroutines, which are provided as a library. You can use certain types of garbage collection as a library. You have dramatic freedom and accessible choices. The possibilities are incredibly inspiring.
Re:Operating System Development in Rust by SwellJoe on Sunday January 11, 2015 @08:11PM (#8872035)
In my tinkering with both Go and Rust, and liking the looks of both, I get vague feelings like Go is to Python as Rust is to Perl. This may be damning praise for some folks, but it makes me lean slightly toward Rust more than Go (slightly). There seems to be almost an anti-library culture in Go (i.e. "use the standard library" is almost a mantra in Go) whereas in Rust, there's more than one way to do it (even this early in its existence).

That said, in many ways neither language is like the one I've compared it to, probably in enough ways that it's not a useful comparison for much other than this one metric (the TIMTOWDIness of the language). But, it's how my head is processing these two quite novel (to me) languages; which would make sense, as I've written more code in Python and Perl than probably anything else, so they're the known things I compare these unknown things to.

Re:Operating System Development in Rust by thirsteh on Sunday January 11, 2015 @08:27PM (#8872071)
You could say that Go is Python and Rust is Haskell, because, well, Rust is basically Haskell cleverly disguised as a C-style language so as to not scare away imperative programmers.
Re:Operating System Development in Rust by detrino on Sunday January 11, 2015 @10:13PM (#8872335)
> Rust is basically Haskell cleverly disguised as a C-style language so as to not scare away imperative programmers.

This comment is very condescending. It makes it seem as if C programmers are ignorant and Haskell programmers are enlightened. Haskell is a garbage collected, lazy, pure language which makes it unsuitable for many of the domains C-style languages are used in. These are also qualities not shared by Rust, which may explain why there is less resistance in its uptake by C programmers.

Re:Operating System Development in Rust by naasking on Monday January 12, 2015 @11:31AM (#8874757)
> Haskell is a garbage collected, lazy, pure language which makes it unsuitable for many of the domains C-style languages are used in.

Don't be so sure! [1] You could simply use Haskell as a metalanguage to generate a C program that does what you need, just like they did with copilot. No Haskell runtime needed.

[1] https://github.com/leepike/copilot-discussion

Re:Operating System Development in Rust by thirsteh on Sunday January 11, 2015 @11:10PM (#8872462)
Oh, come on. Don't take things so seriously. There are tons of Haskell programmers who don't know C, too, and Rust is just as much of a way for them to reap the benefits of C as it is anything else.
Re:Operating System Development in Rust by kyllo on Sunday January 11, 2015 @11:33PM (#8872518)
I'd say Rust is more like C and OCaml had a baby.
Re:Operating System Development in Rust by saosebastiao on Sunday January 11, 2015 @11:56PM (#8872578)
An amazing compliment, IMO.
Re:Operating System Development in Rust by agumonkey on Sunday January 11, 2015 @10:06PM (#8872322)
Reminds me of hop and house (haskell based OS) http://lambda-the-ultimate.org/node/299 ~ 2004
Re:Operating System Development in Rust by vezzy-fnord on Sunday January 11, 2015 @08:38PM (#8872110)
Could you elaborate on that? Rust has a powerful static type system, HOFs, is expression-based, has an unusually good pattern matching engine for its intended area, assumes immutability by default and uses a notation for function signatures typically associated with FP, but I don't think those are enough to call it a "cleverly disguised Haskell".

In fact, it has been my observation that the language has been getting progressively less functional since its early days. Not that I consider this to be bad.

Re:Operating System Development in Rust by thirsteh on Sunday January 11, 2015 @08:44PM (#8872122)
Sure -- basically what you said: http://science.raphael.poss.name/rust-for-functional-program...

Of course it's not exactly Haskell, but it's arguably closer to FP than it is to C, yet manages to be approachable to imperative programmers. I think this is fantastic.

Re:Operating System Development in Rust by nightski on Monday January 12, 2015 @03:34AM (#8872935)
That would be a really tough argument to make. It goes to great lengths to give control over memory layout and control and lacks a LOT of the features of Haskell's type system. It's a lot more like a prettier D than Haskell. Not only that with every iteration it has been moving farther away from the FP paradigm.
Re:Operating System Development in Rust by naasking on Monday January 12, 2015 @11:35AM (#8874783)
I think you mean GHC's type system, since Rust is arguably quite close to Haskell 98 in spirit, ie. algebraic types, lambdas, pattern matching, traits = single parameter type classes.
Re:Operating System Development in Rust by Retra on Sunday January 11, 2015 @10:01PM (#8872307)
I think the point is that it seems actively inspired by Haskell -- that the things people like about Haskell are the same things the designers of Rust want in their language.
Re:Operating System Development in Rust by saosebastiao on Monday January 12, 2015 @01:38AM (#8872759)
As far as I can tell, there is some Haskell inspiration in the form of typeclasses (traits in Rust), but almost everything else that resembles FP has a more common denominator in ML. (Even Haskell's type classes have some common lineage with SML Functors)
Re:Operating System Development in Rust by tuxychandru on Sunday January 11, 2015 @08:17PM (#8872046)
Which library provides goroutine like concurrency in rust?
Re:Operating System Development in Rust by krenoten on Sunday January 11, 2015 @08:48PM (#8872134)
With 1.0, rust no longer has a runtime at all, so official support for libgreen was actually dropped. However, between sync::mpsc, sync::TaskPool and sync::Future you can produce similar results.
Re:Operating System Development in Rust by tuxychandru on Sunday January 11, 2015 @09:22PM (#8872199)
All those deal with threads. Rust 1.0 will have multi-threading just like C++, Java, etc. It is very different from how Goroutines work and do not offer similar benefits at all (specifically for network services).

libgreen while it existed scaled very poorly and consensus among rust developers seemed to be that, it cannot be improved without compromising some of the core features of rust like no-GC and zero-overhead calls to C libraries.

Re:Operating System Development in Rust by krenoten on Sunday January 11, 2015 @09:33PM (#8872232)
Even with Go it's a fairly bad idea not to use Goroutine pools for request handling if you're writing low-latency services. You can get isomorphic results with a future pool and channels.
Re:Operating System Development in Rust by tuxychandru on Sunday January 11, 2015 @09:48PM (#8872272)
It is not about whether goroutines need to be pooled. Goroutines work very differently from how OS threads. They are scheduled at the user-level by using non-blocking system calls to perform network IO on multiple OS threads. They are also partially pre-empted on function calls.

Whether goroutines need to be pooled depends on the application. For example, the default HTTP creates ones per connection and seems to be used without any problem in production at a lot of places. Creating them is much cheaper than creating OS threads. In fact, libgreen threads were faster to spawn than libnative ones in rust when it existed.

Rust and Go have different trade-offs when it comes to concurrency and each has its benefits and drawbacks.

Re:Operating System Development in Rust by krenoten on Sunday January 11, 2015 @10:30PM (#8872364)
I'm not saying that a Goroutine is a thread. My point was, you have the ability to write your own systems for your own tradeoffs. Feel free to write a schedulerless coroutine system or an Erlangesque reduction counting scheduler, or even a full reimplementation of the Go scheduler. You can pin Goroutines to threads to ask them to act a little more like them, but that's about as far as you can go. While you are right that Go's system is great for some tasks, there is no reason why Rust can't form a superset of its functionality, in time.
Re:Operating System Development in Rust by tuxychandru on Sunday January 11, 2015 @11:24PM (#8872502)
Whether goroutine-like mechanism is possible in rust without compromising its core values is not clear, since libgreen attempted it and failed.

Something like async..await is in the cards and I guess rust does have plans to implemented it sometime in future, but that will require compiler support and can't be done just in libraries like you claimed in the first comment of this thread. While it will not have same runtime characteristics of goroutines, it'll provide similar benefits to program structure.

All that said, rust definitely offers a lot. I'm only contending the claim that the language is flexible enough to implement something similar to goroutines purely as a library.

Re:Operating System Development in Rust by jaekwon on Monday January 12, 2015 @01:00AM (#8872691)
Huh interesting... how does Go do it under the hood?
Re:Operating System Development in Rust by tuxychandru on Monday January 12, 2015 @01:50AM (#8872774)
This is a good read on the Go scheduler. http://morsmachine.dk/go-scheduler
Re:Operating System Development in Rust by pcwalton on Monday January 12, 2015 @10:13AM (#8874218)
There is nothing that would prevent an implementation of Go's scheduler in Rust, and libgreen duplicated its functionality pretty comprehensively. Rust's scheduler was more advanced than Go's scheduler in some ways—it did work-stealing in a completely lock-free way, for example.

The only fundamental difference between Rust and Go here is in stack management. In Go, goroutines start off with a small stack, and they can grow because the language is now pervasively, precisely garbage collected and all of the pointers into the stack can be rewritten. In Rust, that wasn't an option because it isn't garbage collected; it used to use the old Go approach of split stacks, but the same problems were encountered. There was also significant backlash against the problems that continue to be an issue in Go and were an issue in Rust—the FFI (cgo in Go's case) was slow due to having to perform stack switches, most importantly.

Re:Operating System Development in Rust by tuxychandru on Monday January 12, 2015 @10:50PM (#8878034)
Yes, that's what I meant when I said it not clear whether goroutines can be replicated as a library in rust "without compromising rust's core values". In fact, I mentioned no-GC and zero-overhead C calls.

Since libgreen did have massive stacks and one could not spawn 100s of thousands of tasks without changing system limits like overcommit, it was not really a comprehensive duplication of goroutines.

Re:Operating System Development in Rust by pcwalton on Tuesday January 13, 2015 @09:55AM (#8880176)
> Since libgreen did have massive stacks and one could not spawn 100s of thousands of tasks without changing system limits like overcommit

Well, you could customize the stack size, and we did when running stress tests like that. You don't need to change system settings. The only difference is that you have to know how much stack your "goroutine" is going to need up front.

Re:Operating System Development in Rust by jaekwon on Tuesday January 13, 2015 @06:14AM (#8879086)
This is really interesting. One or both of you all should write a blog post on it because I'm eager to learn more.

I love C. Love Go. Love the idea of Rust though I've never tried it, and I just want to know more.

Re:Operating System Development in Rust by wtf_is_up on Monday January 12, 2015 @09:59AM (#8874158)
Oh no, flashbacks of C++

Want some simple concurrency? Here try boost::asio... or boost::thread... or... libev... or libuv.

Now every project has a different concurrency model woven into it. Why isn't there a good solution in the stdlib for this common need?

Re:Operating System Development in Rust by dragonwriter on Monday January 12, 2015 @10:09AM (#8874203)
> Now every project has a different concurrency model woven into it. Why isn't there a good solution in the stdlib for this common need?

Because every concurrency/parallelism approach has tradeoffs, and there is no one right implementation for all cases, and rusts intended primary use case is low-level and broad enough that there's not even one approach that's probably good enough for most cases.

Re:Operating System Development in Rust by pcwalton on Monday January 12, 2015 @10:08AM (#8874197)
Everything mentioned in the parent post is in the standard library.