[swift-evolution] Stdlib closure argument labels and parameter names

Anton Zhilin antonyzhilin at gmail.com
Thu Jun 23 16:55:57 CDT 2016


Dave Abrahams via swift-evolution <swift-evolution at ...> writes:

> A couple of weeks ago we started to notice that we had some poorly-
named
> closure parameters and argument labels in the standard library, so we
> did a complete audit of the standard library's APIs and came up with a
> preliminary proposal for changes, which we applied in a branch and you
> can review in https://github.com/apple/swift/pull/2981.  Let's please
> carry on further discussion here rather than in the pull request, 
though.

I don't like that more clutter is added to the call site. We can surely 
find shorter and more descriptive names. Remember that most people 
already know what filter, map and reduce means, we don't need to explain 
them.

My suggestions:

filter(where:)
map(over:)
reduce(applying:)
sort(by:)
forEach(do:)

Remember that these functions came from functional languages, where 
function names tend to be brief, and it is considered one of their 
advantages.

Data flow is an area where code becomes the less understandable when 
more visual clutter is added. In my opinion,

array.filter(isEven).map(square).reduce(sum)

reads better than

array.filter(suchThatTrue: isEven).map(applyingTransformation: 
square).reduce(accumulatingResultBy: sum)

What do you think?



More information about the swift-evolution mailing list