4 ms·
Loops impose, and guarantee, ordered traversal of a collection. Maps do not. This means that maps can sped up by dividing up the collection into smaller parts a
by jacques_chester 13y ago
Loops impose, and guarantee, ordered traversal of a collection. Maps do not. This means that maps can sped up by dividing up the collection into smaller parts and mapping each of them in parallel.
For a language that has concurrency as a central design motivation, it's an unfortunate omission.
As we say in the database world: think in sets, not in arrays.
- cmccabe 13y agoIt's an imperative language, not a declarative one. The issue is not ordering (traversal over maps in golang is not ordered), but side effects. SQL is great. Not all languages have to be SQL.
- jacques_chester 13y agoAssembler is great too, but not all languages have to be assembler. The modern looping construct imposes order not by design, but by historical accident. Working with a collection of data in assembler works by proceeding through memory addresses in linear order and then jumping back to the top. That pattern got lifted into higher level languages via the DO loop in Fortran. It's an example of path dependency. Why do we assume that loops are the only natural way to deal with collections? Because that's just how the path of history unfolded. I think the die was cast when it turned out to be easier to build Turing machines than lambda calculators. Edit: I don't know who downvoted you, but I hope it was an accident.
- icebraining 13y agoIt's an imperative language with side-effects, unordered mapping would break expectations and produce buggy code. You can still achieve those speed ups, you just need to be explicit about the division (e.g., by creating a channel, launching goroutines and then collecting the results). https://sites.google.com/site/gopatterns/concurrency/parallel-for-loop https://sites.google.com/site/gopatterns/concurrency/paralle...
- jacques_chester 13y agoI'm not talking about what Go is; I'm more interested in what it might have been. There's nothing in the law that prevents mapping with side effects. If the side-effects don't require a particular order, why constrain them?
- icebraining 13y agoI'm not talking about what Go is; I'm more interested in what it might have been. Well yes, but there are certain core concepts that define Go, and being imperative with side-effects is one of them. If we drop that, then we're no longer discussing Go but some hypothetical language. There's nothing in the law that prevents mapping with side effects. If the side-effects don't require a particular order, why constrain them? But they aren't constrained, they just aren't built-in. Go has loops, not maps, but if one wants to make a mapping function, the link I posted shows there's no constraint in having it execute out of order.
- jacques_chester 13y agoI think we're just restating our arguments. I'm happy to leave it here.