[swift-evolution] API Guidelines: dropFirst?

Jonathan Hull jhull at gbis.com
Thu Jun 16 06:42:35 CDT 2016


I actually think we should use ‘mapped’, ‘filtered’, and ‘reduced’ instead of the “Terms of Art”.  They start with the same words, so anyone looking for ‘map’, ‘filter’, and ‘reduce’ will see them in the autocomplete.

The signatures are also different, so:

let newList = list.map(…)

would throw an error because I have the signature wrong.  Given the consistent naming rules, ‘mapped’ will be tried fairly quickly (especially with auto-complete).  If we are extra worried, we could put in a diagnostic/fixit to teach the ‘mapped’, etc… version.

Seems like needless (and confusing) inconsistency otherwise...

Thanks,
Jon

> > What is the rationale behind the name dropFirst()? Being a non-mutating method it should clearly be e.g. droppingFirst() according to the API Naming Guidelines.
> 
> Like many `Sequence` and `Collection` operations, `dropFirst()` is a result of the "term of art" exception, which is implied by the "Use Terminology Well" section of the API Guidelines: <https://swift.org/documentation/api-design-guidelines/#use-terminology-well <https://swift.org/documentation/api-design-guidelines/#use-terminology-well>>
> 
> Many languages use `dropWhatever` or `drop_whatever` for operations which return some sort of list with some of its leading or trailing elements removed. For instance:
> 
> * Ruby (which I happen to have in Dash) has `drop(n)` and `drop_while` methods.
> * Haskell has `drop n`, `dropWhile`, and `dropWhileEnd` functions.
> * Scala has a `drop(n)` method.
> * R has a `dropFirst` function.
> 
> The standard library has chosen to break its usual patterns in order to maintain consistency with languages like these.
> 
> Personally, I believe the term of art exception has been misapplied in this area of the language; the precedents are not very strong, and the resulting APIs form a patchwork of inconsistent names rather than a coherent family. The term of art exception increases the clarity of calls like `map` and `filter` where the names are truly universal, but it impedes the clarity of the whole family of `first`/`prefix`/`suffix`/`last` calls, and the names should be revisited and rationalized. But that hasn't happened yet.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160616/604cbaa8/attachment.html>


More information about the swift-evolution mailing list