by smegel · 13y ago · 0 comments
Yes, Scala has loop/react ... but they are really just a different way of writing callbacks, and don't allow you write truly synchronous-style code over an event based system.
Simply have each of those methods you wish to call return a future...
[1] https://github.com/scala/scala/blob/v2.10.2/src/library/scal...
The style one can program in and the style it is implemented isn't connected the way you think it is.
And no, Scala "doesn't have" loop/react. Unlike Go, where people seemingly put random stuff into the language, it's just a bog-standard library.
"The style one can program in and the style it is implemented isn't connected the way you think it is."
The above might be alluding to techniques for pretending to have these language features when one does not. You can write CPS manually, and you might even be able to make a machine apply the CPS transformation automatically to your procedural code. Neither of these things sound particularly fun, compared to the alternative of writing procedural code and then debugging the code that you've actually written. It's little help that you have to return every once in a while to avoid a StackOverflow due to the language's embarrassing lack of TCO.Edit: Apparently if you use Squawk you can have green threads. Can you have OS threads as well?
This whole sort of back and forth exchange of escalating condescension is not rare on the internet, but I was surprised that dino wouldn't actually tell anyone why we were wrong. Generally I've found this quote http://bash.org/?152037 to be more or less true; asserting that a system is incapable of things it is capable of is met with people pointing out how to make it do those things. In this particular instance the response from dino involved much more effort than a simple lmgtfy link while accomplishing dramatically less in the promotion of his faith, or even the promotion of any sort of knowledge at all.
This feature is a little obscure, and one could easily spend a great deal of time writing Scala professionally without ever passing "-P:continuations:enable" to anything. I believe that one would be missing out.
TCO is a runtime property, not a language property.
Anyway, you have clearly not been doing your research and its not my job to do it for you.
Bye.
Edit: I am still seeking the legendary JVM implementation with TCO. I guess the argument is something like, oh well at some point in the future some JVM could conceivably have that feature, therefor it is wrong to say that Scala does not have it! Rather than writing code that assumes Scala is a complete joke of a functional language, one could simply write the code the natural way, verify that it compiles, and then wait until a JVM with TCO exists, so that it will stop crashing! In the mean time, one can enjoy the entertainment provided by Scala's inability to compile shift in an if statement without an else clause. Truly I am writing code exactly as I would if(it_was_synchronous) else { cpsunit }.
I feel as though you told me reset and shift, although you did not. So thanks for that!
The implementation determines what happens when synchronous, blocking code, well blocks.
In Go it yields to another green thread (Goroutine).
In any language implemented on the JVM (including Scala) you block an OS level thread.
The way languages without green thread support allow non-blocking, event based code is through callbacks, which can get pretty horrendous in large, complex programs.
> Unlike Go, where people seemingly put random stuff into the language, it's just a bog-standard library.
I'm not sure why that is relevant (Actors seem a pretty core part of Scala), but I guess it is unsurprising that a mere library on top of the JVM is still constrained by the kind of concurrency supported by that platform, i.e. the lack of green threads.
Wrong. Whether JVM implementations use green threads or system threads is an implementation detail. There are implementations for both cases.
You realize that many JVM implementations started with green threads in the early days and abandoned them not much later? There is a reason for that.
> The way languages without green thread support allow non-blocking, event based code is through callbacks, which can get pretty horrendous in large, complex programs.
Wrong. I repeat, the underlying threading model does not necessarily enforce some style of API.
> I'm not sure why that is relevant (Actors seem a pretty core part of Scala)
Actors are a library, just like Scala's async/await, the Future/Promises library, the continuation library, Java's Fork/Join library.
Actually, Scala just replaced its “official” Actor library in the last release. Go will be stuck forever with its ad-hoc stuff which has been hard-coded into the language.
> it is unsurprising that a mere library on top of the JVM is still constrained by the kind of concurrency supported by that platform, i.e. the lack of green threads
LOOOOOOOOOOOL. Since when are green threads the “new best thing ever!!!11!!”? Did I miss a memo here?
You know what? Wake me up when Go has fixed their broken scheduler. Until then, I just keep watching how the JVM embarrasses Go on pretty much every concurrency and scalability workload.
Obviously it is an implementation detail, and for any JVMs that support green threads (none of the major ones do), then it would be a different matter entirely.
> You realize that many JVM implementations started with green threads in the early days and abandoned them not much later? There is a reason for that.
Java was created in the mid-90s before every man and his dog was trying to solve the c10k problem on a $5/month VPS. Hardly surprising.
> Wrong. I repeat, the underlying threading model does not necessarily enforce some style of API.
But it does allow for it, or make it easy. Why do you think Scala has both blocking, and "event based" (loop/react) API's?
> Since when are green threads the “new best thing ever!!!11!!”? Did I miss a memo here?
Quite possibly, you must have been living under a rock if you haven't heard of callback hell in Node.js. Funny because Node was the coolest thing ever a couple of years back, how times change.
> You know what? Wake me up when Go has fixed their broken scheduler. Until then, I just keep watching how the JVM embarrasses Go on pretty much every concurrency and scalability workload.
Java has great MT concurrency. It's light-weight concurrency (NIO) is about as good or bad as any other event-based systems out there. What is lacks (my original comment) is the ability to write event-based code using a synchronous, blocking style (without callbacks).
The only contenders there are Go, Haskell, and possibly some of the scripting language extensions (Python/Gevent, Perl/Coro).
And if by "broken scheduler" you mean it's lack of preemption...then I would say rethink your design, you should be handing long-running jobs to a work queue anyhow.