For what it's worth, I'll take for loops over list comprehensions any day of the week. I just find it a lot easier to read.
arr2 := []int{}
for i := range arr1 {
if arr1[i] > 9 {
arr2 = append(arr2, arr1[i] * 2)
}
}
Is more readable than these? var arr2 = arr1.Where(x => x > 9).Select(x => x*2);
var arr2 = from x in arr1 where x > 9 select x*2;
arr2 = [x * 2 for x in arr1 where x > 9]
(setf arr2 (loop for x across arr1 when (> x 9) collect (* x 2)))
I honestly can't imagine by what measure any of the latter ones could be harder to understand the former. And as the complexity of the expression increases, I only see the advantage increasing typically (though often it pays to split it into multiple comprehensions, just like a loop that does too much).It’s not inherent complexity though, just personal preference. I grew up writing for loops so they’re second nature to me and I grok them instantly in a single pass, whereas some list comprehensions require a re-read (particularly if they’re nested).
Different strokes, that’s all.