|
|
|
|
|
by tester756
974 days ago
|
|
>eg `for` loops are being replaced by `foreach` loops,`map` and `filter` operations, etc. These tell the compiler/interpreter that you want to do some operation to all the items in your datastructure, leaving it up to the compiler/runtime whether and how to parallelize the work for you. There's difference between doing it in order 1, 2, 3 and 3, 1, 2. foreach will not be replaced behind the scenes into multithreaded version since it changes behaviour. for is replaced with foreach because usually you dont need index and foreach is just handier and safer, that's it. .NET's std lib has Parallel.ForEach for such a thing. We really don't need magic to write multithreaded code. All we need is just really, really well designed APIs and primitives. |
|
It only (meaningfully) changes behavior if you're both iterating over an odered datastructure and the body of your loop has direct or indirect side-effects. (like printing, writing to a file, making network requests, etc)