When learning Swift, I didn't realise that we can access nested tuple values using the tuple.0
or tuple.1
syntax. I also really liked the array.first
and array.last
properties similarly and since these avoid the indexing offset by 1. So I thought it could be more readable/understandable to add tuple labels for a public API for beginners using the function. In case the internal API changes and the first tuple value no longer returns an element that a user expected (a particular type, for instance), the labels could be clearer as an abstraction.
For example:
public mutating func next() -> (element1: Base1.Element,
element2: Base2.Element)? {
I received feedback:
-
Generic labels such as
element1
andelement2
don't really add any clarity over.0
and.1
. -
These labels don't improve the users' understanding, because they don't convey any useful information. It's impossible for us to give the tuple elements descriptive names because at this level of abstraction we have nothing to go on. To quote the API Design Guidelines:
Omit needless words. Every word in a name should convey salient information at the use site.
Open to your thoughts and feedback. I can see that the labels don't add much in this instance but maybe they could be useful in the future.
Thanks in advance