| In line with this, list comprehensions are one area of python I find particularly clunky. They work fairly well for a single map or filter operation, alright for both mapping and filtering, and are absolutely unreadable for anything more complicated. A big part of this in my opinion is how they scramble the flow. Instead of taking a piece of data and performing successive operations on it, both in logic and in syntax, you have their 'literate' mess that requires you to start reading in the middle of the line and alternate moving your cursor back and forth. Consider: getNumbers()
.map(x => x×2)
.filter(x => x % 6 == 0)
.map(x => x^2) get numbers. double them. filter for divisibility by 6. square them. versus [x^2 for x in x×2 for x in getNumbers() if x % 6 == 0] get the square of the doubles version of getNumbers values, but only if those doubles are dividable by 6. But wait are the doubles dividable by 6 or the squares? Maybe some people are fine with looking at what operations are being performed on the data before even knowing what the data itself is, but that for me seems incredibly backwards. Plus it also gives rise to order of operations ambiguities. Nobody could mistake the ordering in JS, but I honestly have no clue how that python would evaluate. (using carats because hn cant format code) Edit- This came to mind because of a flattening list comprehension I encountered earlier today: #flatten the lists flattened_list = [y for x in list_of_lists for y in x] I've spent quite some time staring at this and I still have no clue what it's actually doing. I've never had that with JS operator chains. |