VirtusLab / avocADO

Safe compile-time parallelization of for-comprehensions for Scala 3
https://virtuslab.github.io/avocADO/docs/index.html
Apache License 2.0
87 stars 5 forks source link

To use a more intuitive and straightforward name/alias #94

Closed baldram closed 5 months ago

baldram commented 6 months ago

Hello Dear Maintainers, thank you for your work on this incredibly useful library!

I would like to propose an improvement in order to use a more intuitive name that directly relates to the functionality that the library provides.

I understand the origin of the name and its references to Haskell. However, from the perspective of Scala, not everyone has such roots, and without additional explanations, the name ado doesn't say much. A new person in the project, seeing something like this in the code, may feel lost. Seeing the word parallel or parallelize, they will easily understand what a given code block does.

If this is a good idea and is well received, creating an alias would likely be a solution, providing backward compatibility. Taking it a step further, standardising and adding the @deprecated annotation to ado would be an additional option to consider.

I would also refer to @szymon-rd's presentation from Scalar 2023, which teaches us that we may want our code to be easier to read and libraries designed to be intuitive: https://www.youtube.com/watch?v=nA9gRGpOOJc

Finally, an example for applicative-for would look like that (using parallel, parallelize, or similar).

val run: IO[Int] =
  parallel {
    for {
      a <- doStuff1
      b <- doStuff2(a)
      c <- doStuff3
    } yield combine(a, b, c)
  }

What do you think?

KacperFKorban commented 6 months ago

Hi, we had an internal vote regarding changing the name among the maintainers and the results are:

in favour: 1
against: 0
abstain: 0

Seriously though, I am definitely for the change. Also since readability is the main concern, we should definitely deprecate ado then.

One additional improvement we can make here is to make the API consistent with kitlangton/parallel-for, which is the Scala 2 equivalent of this library. He uses par and par1. However, that might require some more thought, since kitlangton/parallel-for uses different semantics for the transformations - ones that are not implemented here yet (#9).

KacperFKorban commented 5 months ago

I have an idea for a slightly different naming scheme:

What do you think? @baldram

baldram commented 5 months ago

Hi Kacper, thank you for your response. I'll respond sequentially to both answers.

internal vote regarding changing

😄

He uses par and par1. However, that might require some more thought,

To be honest, I would save effort here. If there are too many ways to use the library, it will become difficult to understand. It's better to stick to one good and well-thought-out option. And if someone is migrating from the Kit's library, it's just one batch replace in the entire project, and the name can be changed. Additionally, I would like to point out that Kit also acknowledged that the names he uses should be abandoned and changed to a new one, bluntly stating that the current one is "pointlessly terse". He tentatively accepted "parallelize".

Please see a discussion here: https://github.com/kitlangton/parallel-for/issues/8

ado -> parOrdered, parUnordered

How about parallelize and parallelizeUnordered ?

Thanks to the documentation and code completion, someone can find the "unordered" variant, which from the Scaladoc description will have the necessary information that it's a more aggressive version. The basic one, without an additional suffix, can be simply named, and additionally, Scaladoc will explain what this variant does and refer to the second option if someone wants to achieve something more.

I'm not sure if we want to use "pointlessly terse" abbreviations. Those few characters won't save much, and it's still the beginning of a code block; there won't be anything else on that line. A simple and self-explanatory name will make it so that someone seeing such code will immediately understand what's happening, even if they encounter Avocado for the first time in their life.

What do you think?

PS: Were you at Scalar this year? The leitmotif was "Lean Scala". Let's demystify Scala, let's not complicate it unnecessarily. Scala for people ;)

kitlangton commented 5 months ago

This all seems like much ado about nothing.

...

Just kidding. I only wanted to make that pun.

UPDATE: Oops. And now I hit enter too early.

I'm for the somewhat more verbose/clear variant! I'm all in for parallel/parallelize 😛 The only danger is that I imagine parallel ranks among the top common-yet-misspelled words—alongside balloon and misspelled, its tricky double-lettered brethren—but autocomplete should help out.