[swift-evolution] rename dropFirst() and dropLast()

Kevin Ballard kevin at sb.org
Mon Dec 28 18:25:05 CST 2015

On Mon, Dec 28, 2015, at 04:23 PM, Kevin Ballard wrote:
> On Mon, Dec 28, 2015, at 04:19 PM, Michel Fortin wrote:
> > Le 28 déc. 2015 à 19:02, Kevin Ballard via swift-evolution <swift-evolution at swift.org> a écrit :
> > > On Mon, Dec 28, 2015, at 03:53 PM, Michel Fortin via swift-evolution wrote:
> > >> Following the new API guidelines, shouldn't the name be either `droppingFirst` or `excludingFirst`? That would solve your problem, right? Many things still need to be adapted to the new conventions.
> > >> 
> > >> https://swift.org/documentation/api-design-guidelines.html#be-grammatical
> > > 
> > > That's not what the conventions say. They say non-mutating phrases should read as noun phrases when possible. But `droppingFirst` isn't a noun phrase. This means things like `index.successor()`. It also says that if there is no good noun phrase to use then imperative verbs are acceptable, which means it will stay as `dropFirst`.
> > 
> > Really? The convention says: "When a mutating method is described by a verb, name its non-mutating counterpart according to the “ed/ing” rule, e.g. the non-mutating versions of x.sort() and x.append(y) are x.sorted() and x.appending(y)."
> > 
> > Are you telling me that because no one bothered *yet* writing a mutating version of this method the "ing" rule does not apply? That it will apply only the day someone will write mutating method called `dropFirst`? This interpretation of the guidelines does not make much sense.
> Oh my bad, you're right. I read the first two rules, glanced ahead and saw it talking about other specialized variants (e.g. boolean methods/properties) and managed to not notice what the third rule said.
> That said, `droppingFirst` sounds pretty weird to me. "drop" (and the related verb "take" that we're not using) has precedent in multiple languages (Rust and Haskell come to mind) to mean "return a new sequence that skips the first N elements". And I'm not aware of any language that sets precedent for the verb "drop" to mean "mutate the receiver".

To add to this, existing Swift and Obj-C precedent says the mutating method will be named with "remove" (e.g. `removeFirst`). So the logical name for this based on the grammar rule is `removingFirst`, but that also sounds weird to me.

-Kevin Ballard

More information about the swift-evolution mailing list