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

Daniel Duan daniel at duan.org
Tue Dec 29 19:46:02 CST 2015


The fact that SequenceType is non-mutable and does not have the remove* method has been clear from the start. In *effect*, however,  concrete CollectionTypes do have both .removeFirst() and dropFirst().

Replacing .dropFirst() with a “better” verb phrase such as .skipFirst() raises a new concern:

The API Guidelines *could* make Swift 3 users to expect consistency when it comes to mutating/non-mutating pair APIs *wherever applicable*. This is a great goal for a programming language. Taking this away from Array just because it happens to be a SequenceType? That’s Robbery. 

- Daniel

> On Dec 29, 2015, at 4:29 PM, Kevin Ballard <kevin at sb.org> wrote:
> 
> On Tue, Dec 29, 2015, at 03:39 PM, Daniel Duan wrote:
>> I suppose it’s appropriate to go into grammars since we are in a language mailing list :)
>> 
>> Present Participle is just an official name for “verb in present tense”, as in “I am *writing* an email”. Let’s put the example from API Guideline to test. I hope you agree that “someText.strippingNewlines()” as a non-mutating method name is grammatical *somehow*. So, does it read as
>> 
>> 	self is *stripping newlines*, here’s X.
>> 
>> …or does this make more sense…
>> 
>> 	*stripping newlines* from self gives X.
>> 
>> ?
>> 
>> I tend to think the latter. There’s a fancy name for it as well: gerund phrase.
> 
> I don't read it either way. As suggested in my previous email, I'd read this as "transforms someText by *splitting newlines* (and returns the result)". It's not entirely clear how to classify this usage (since grammar is confusing), but it's kind of a moot point because Wikipedia says:
> 
>> The distinction between gerund and present participles is not recognised in modern reference grammars, since many uses are ambiguous.
> 
> And it doesn't really matter anyway because the guidelines don't say that the non-mutating variant has to read as a noun phrase, it just says to name it using the appropriate -ed/-ing ending. And in the case of strippingNewlines(), this makes sense, as it's the non-mutating counterpart to stripNewlines().
> 
> But in the case of dropFirst(), this is not a non-mutating counterpart to removeFirst(). dropFirst() is defined on SequenceType, which has no removeFirst(). If anything, removeFirst() is a mutating version that's derived from dropFirst() (although not really, since removeFirst() is named after removeAtIndex() and the only naming relation it has to dropFirst() is re-using the same "First" suffix).
> 
> -Kevin



More information about the swift-evolution mailing list