News for hackers. Stuff that matters.
Re:Async Ruby by sizediterable on Saturday October 30, 2021 @01:18PM (#29050460)
> any blocking operation (a method where Ruby interpreter waits) is compatible with Async and will work asynchronously within Async code block with Ruby 3.0 and later.

That's pretty magical. Does this mean it would be possible to implement structured concurrency [0], but without the function coloring problem?

Regardless, I think I prefer how this looks from a code read/writeability perspective compared to Zig's or Swift's (and potentially future Rust's [2]) approaches.

[0] https://vorpus.org/blog/notes-on-structured-concurrency-or-g...

[1] https://kristoff.it/blog/zig-colorblind-async-await/

[2] https://blog.yoshuawuyts.com/async-overloading/

Re:Async Ruby by brunosutic on Saturday October 30, 2021 @01:27PM (#29050552)
Async Ruby is colorless!

It's obvious from the examples provided in the post. For example, you can use the method `URI.open` both synchronously and asynchronously.

It's something I didn't want to mention in the article because it's a relatively advanced async concept, but yea - Async Ruby is already colorless and it's great.

Re:Async Ruby by gpderetta on Saturday October 30, 2021 @03:15PM (#29051524)
IIRC ruby has first class continuations, so it doesn't have to deal with any async/await nonsense.
Re:Async Ruby by brunosutic on Saturday October 30, 2021 @03:28PM (#29051609)
That's right - Async Ruby uses fibers (stackful coroutines) as a concurrency primitive. There's a lot to say about this, but the end result is that we get to write simple synchronous code and it can run asynchronously.
Re:Async Ruby by g8oz on Saturday October 30, 2021 @09:42PM (#29053775)
N00b question: would the fibers being introduced in PHP 8.1 enable the same functionality in that language?

https://php.watch/versions/8.1/fibers

Re:Async Ruby by nixpulvis on Saturday October 30, 2021 @04:42PM (#29052143)
On a tangential note.

> Async Ruby is colorless!

I find it deeply irritating that this is how we choose to describe things these days. Rather than talking about modality, or even using a few more words to describe the actual differences in terms of the underlying programing language models.

Telling me that Ruby's async is colorless implies that I know about the description of programming models as "colors" of code, which was just some random analogy someone came up with which caught on. Nothing about this has anything to do with color. Even syntax highlighting doesn't really fit. This is akin to particle physicists getting cheeky and calling one of the quantum states "color" when it has nothing to do with wavelength (correct me if I'm wrong).

This is an appeal to stop trying to be so cute. Thank you.

Re:Async Ruby by sanderjd on Saturday October 30, 2021 @07:24PM (#29053086)
It's jargon. This is an industry board. Jargon is par for the course.
Re:Async Ruby by jazzyjackson on Saturday October 30, 2021 @08:53PM (#29053566)
What do musical scales have to do with it? (Modality :P)

"coloring" goes back before a few blog posts, it was probably popularized with programmers that keep up with crypto, as 'colored coins' are described in an influential paper right around the creation of Ethereum (Vitalik is one of the authors)[0], but I found some earlier references too, like coloring a complex plot to add a dimension [1], so carrying it over to computer programming, you have functions that have otherwise identical signature that you need to distinguish, so you make them different colors.

[0] https://docs.google.com/a/buterin.com/document/d/1AnkP_cVZTC...!

[1] https://en.wikipedia.org/wiki/Domain_coloring

Re:Async Ruby by tyrfing on Sunday October 31, 2021 @02:09AM (#29054832)
Coloured Petri Nets predate both and are relevant to crypto, I don't know enough to say if the idea was math/compsci jargon prior to that as well.

https://en.wikipedia.org/wiki/Coloured_Petri_net

Re:Async Ruby by jazzyjackson on Sunday October 31, 2021 @04:36AM (#29055478)
Thanks! Didn’t know about Petri nets, makes me wonder if this all didn’t start with Red/Black binary trees, so named because that’s the two colors of ink they had on hand, cited 1978:

https://softwareengineering.stackexchange.com/questions/1166...

Re:Async Ruby by bradgessler on Saturday October 30, 2021 @05:12PM (#29052333)
What is “colorless” suppose to mean? This is the first time I’ve seen it used.
Re:Async Ruby by justsomeuser on Saturday October 30, 2021 @08:56PM (#29053583)
It references the function return type:

Colored = Promise<T>

Colorless = T

In "colorless" async/await, async functions are implicit (no async keyword), and when called, the compiler auto-unwraps the promise, so everything looks like "sync" code but any function stack could "save and resume" at an "async point".

Re:Async Ruby by bradgessler on Tuesday November 09, 2021 @02:00PM (#29165898)
Too bad the Zeitgeist didn't land on "Typed" vs "Untyped".
Re:Async Ruby by vmarquet on Saturday October 30, 2021 @05:29PM (#29052427)
I think it's a reference to this blog post https://journal.stuffwithstuff.com/2015/02/01/what-color-is-...
Re:Async Ruby by auno on Sunday October 31, 2021 @07:11AM (#29056152)
Which in turn is making a reference to an even older post at https://ansuz.sooke.bc.ca/entry/23.
Re:Async Ruby by jsnell on Saturday October 30, 2021 @05:29PM (#29052428)
Re:Async Ruby by brunosutic on Sunday October 31, 2021 @04:46AM (#29055517)
Red-black tree, a well-known algorithm also uses color references

https://en.wikipedia.org/wiki/Red–black_tree

Re:Async Ruby by DangitBobby on Saturday October 30, 2021 @03:19PM (#29051547)
As someone who operates mainly in Python, I am so jealous. As far as I'm aware [1], you have to re-write your tooling to take advantage of async in Python. Does anyone have any insight into why Python async doesn't work the same way? Does it come down to fundamental language differences?

1. https://stackoverflow.com/a/63179518/4728007

Re:Async Ruby by brunosutic on Saturday October 30, 2021 @03:36PM (#29051684)
> Does it come down to fundamental language differences?

No, I don't think there's anything fundamentally different.

Ruby 3.0 implements a "fiber scheduler" feature that enables "colorless Async". Fiber scheduler is an obscure Ruby feature, but the end result is brilliant. It was also a huge amount of work.

Side note: Fiber scheduler was implemented by the same guy who created Async Ruby - Samuel Williams. This guy is the mastermind (and master-coder) behind this project.

Re:Async Ruby by pansa2 on Saturday October 30, 2021 @04:26PM (#29052026)
> Does anyone have any insight into why Python async doesn't work the same way?

Ruby async seems to be implemented using stackful coroutines. IIRC Guido has been opposed to adding these to core Python, preferring stack-less coroutines because they require every yield-point to be explicit (i.e. marked with `await`).

There are libraries for a python that support stackful coroutines, such as gevent.

Re:Async Ruby by sizediterable on Saturday October 30, 2021 @04:47PM (#29052165)
I'm optimistic that this will be less painful as more of the Python ecosystem becomes async-friendly. We have `aiohttp` as a suitable replacement for `requests`, and major libraries like Django (not ORM yet), Flask, FastAPI, SQLAlchemy now have async support as well.
Re:Async Ruby by DangitBobby on Saturday October 30, 2021 @05:55PM (#29052598)
It has already gotten less painful as time goes on. However, in my experience so far if I need e.g. Django to use Google Cloud Storage for media storage, I need to write my own shims that marry together an async alternative to Google's Python SDK (which I have no idea if there are any plans for async support) with third part django packages that I'd normally use. The experience isn't terrible, but I end up spending a lot of time trying to making consistent calling conventions.

And I think I've come to the conclusion that any re-usable code I write for IO should just be written async with magic sync wrappers for use in sync contexts.

Re:Async Ruby by azth on Saturday October 30, 2021 @03:48PM (#29051786)
The first reference is the same route that Java is taking with its green thread implementation by means of Project Loom[0].

[0] https://cr.openjdk.java.net/~rpressler/loom/loom/sol1_part2....

Re:Async Ruby by oezi on Sunday October 31, 2021 @04:45PM (#29060245)
I am actually not a 100% how far the compatibility shows. When I test Async gem with httparty and open-uri, there is no speed-up when comparing with threads:

https://gist.github.com/coezbek/07061fb7de2b036bf5c69f8a8b8c...

I might be using it wrong...

Re:Async Ruby by oezi on Sunday October 31, 2021 @05:46PM (#29060750)
Ha! This only works with Ruby 3.0, because only since then are standard library function using async-compatible methods internally.