2 ms·
Many people still argue that loops are more readable than collection operations ("comprehensions" in Python). And many of us here, myself included, would argue
by michaelteter 3y ago
Many people still argue that loops are more readable than collection operations ("comprehensions" in Python). And many of us here, myself included, would argue that there are plenty of perfect cases for 1-line collection operations (such as each/map etc.)
Any langauge feature can be used well or poorly, so singling out some of these newer language features - just to show bad use cases - is kind of misleading. It would be better to stop using intentionally inflammatory words like "useless" and instead show "when to use".
The one-line "endless" functions are perfect for actual functions that fit on one line without additional punctuation.
For example, custom string manipulation utility functions read like documentation.
def string_of_tags(tags) = tags.join(', ')
def fullname(person) = [person.first_name, person.last_name].join(' ')