Indefinite pronouns got me thinking about concurrency patterns a bit more:
- any
- all
- some
- none
- one
- few
- fewer
- many
- more
- neither
- most
- such
That’s not all of them, but it’s a good start. Indefinite pronouns, roughly speaking, are what allows us in English to signify operations on a list somewhat less… definitely… than otherwise.
These are the parallel equivalents of the Boolean operators we all know and love. And, or, not, so, xor, nand, nor, etc. Of course many of the Boolean operators operate most naturally on a list of two items, and the indefinite operators work well on lists of indeterminate length (in some cases, literally indeterminate, in that they could work on a list that hasn’t been counted at all).
Now, the difficulty here is that with software, indefinite logic requires us to do a bit more bookkeeping than straight Boolean logic. For instance, when I do something like “a and b” with Boolean logic, I just evaluate a. If a returns true, I evaluate b. If b returns true, the whole statement is true. Everything can be done sequentially, and programmers know to rely on the short-circuiting nature of the operation.
On the other hand, if I say “all a, b” I kick off concurrent evaluations of both at the same time (even if under the covers the machinery that takes care of this runs sequentially, or optimizes to run the faster one first or the more likely to fail one earlier). If b immediately returns false, I need some way to tell a to stop evaluating, which might save considerable time and effort.
The Go programming language has some nice primitives built in for both operations (e.g. kicking off parallel computations, and for communicating between the various sub-processes). The “go” term indicates parallel execution, and the <- operator on a channel indicates communications back.
Of course with a thousand nested parallel calls, interspersed with plain old Boolean logic, there may be quite a bit of this going on, but it also may happen that most the calls get shut down before doing much.
The code might look something like this:
and(a, b, c, all(c, d, any(e, f, g)), some(h, i))
Here, the term and indicates sequential execution, the term all can be thought of as a parallel short-circuiting and, the any can be thought of as a parallel short-circuiting or, and the term some can be thought of as another variety of parallel or, which maybe doesn’t short-circuit as quickly.
I think programmers would grok this if it were presented in a reasonable fashion.