[swift-evolution] [Review] SE-0023 API Design Guidelines (when to use properties)

Joseph Lord joseph at human-friendly.com
Sat Jan 30 19:46:52 CST 2016


On 27/01/2016 23:50, Dave Abrahams via swift-evolution wrote:
>
> on Wed Jan 27 2016, Howard Lovatt <howard.lovatt-AT-gmail.com> wrote:
>
>> I would say that if it doesn't have arguments and doesn't mutate then it
>> should be a property, since it will read better and is flexible (you can
>> switch between a stored and calculated property without affecting the
>> external interface easily).
>
> We had at least one member of the guidelines group initially felt *very*
> strongly that we should use (basically) that criterion.  But then, in
> our survey of the standard library, we found that applying it left us
> with many properties that he wasn't comfortable with, such as
> `sequence.iterator` (today's `sequence.generate()`).

I think that if you get a new instance of something back that will be 
distinct from the one you will get if you access it again then it should 
be a method and not a property. In a way the state has changed because 
it won't give you the same instance. This would keep generate() in the 
method category (for single use ones anyway).

Joseph



More information about the swift-evolution mailing list