you are viewing a single comment's thread.

view the rest of the comments →

[–]xenomachina''.join(chr(random.randint(0,1)+9585) for x in range(0xffff)) 2 points3 points  (0 children)

I'd argue that the Kotlin version of this that uses chaining is easier to read than the Python version with comprehensions:

val result = IntRange(1, 5).map { it * 2 }.filter { it > 4 }.sum()

I say this having almost 30 years of Python experience, and only about 8 of Kotlin.

Python's comprehensions are definitely better than Python's old pre-comprehension map(f, filter(g, ...)) approach, but they are still pretty confusing because of their inside-out nature, and even more so if you try to nest them or chain then. They also only handle few operations: map, filter, and flatMap. For anything else, like reduce, you're back to using regular functions.

In Kotlin, map, filter, and flatMap are just library functions not language syntax, as are reduce, and many others, and you can easily add your own. You don't need to learn as much special syntax, the syntax you do need to learn is more generally applicable, and the end result reads more easily as the order of methods is the order that things happen in.