[swift-users] They had parens upon thars

Dave Abrahams dabrahams at apple.com
Tue Aug 2 19:44:14 CDT 2016


on Tue Aug 02 2016, Travis Griggs <swift-users-AT-swift.org> wrote:

> Chapter 1:
>
> Coming from a Smalltalk background, I was enjoying added all kinds of
> properties to basic number types, for example:
>
> extension Double {
>     var rounded:Double {
>         return round(self)
>     }
> }
>
> Chapter 2: 
>
> I upgraded to XCode8Beta4 yesterday and firstly got to change all of
> UIColor.someColor() calls to UIColor.someColor accessors.
>
> Secondly I got to scratch my head for a while regarding the cryptic
> compiler errors I was now getting from my Double.rounded extension. I
> finally found that FloatingPoint has added a rounded()
> method. Creating a conflict with my rounded property (I presume). So
> removed my extension and changed all of the accesses of rounded to be
> calls to rounded(), as well as change the rounded properties I had
> made for my own Angle and Duration enums for to rounded() methods for
> consistencies sake.
>
> Chapter 3:
>
> At this point, I felt a bit like a Sneetch (Dr Seuss). I was basically
> shuffling empty parens around my code base to make the new version
> happy.
>
> I realize it can probably never be black and white, but is there at
> least some guidelines as to when a property ought to be a niladic
> method, and when a niladic method ought to be a property?

These were the (unfortunately somewhat fuzzy) conclusions of the Swift
API guidelines working group when we tried to tackle the issue, FWIW:

https://gist.github.com/dabrahams/b6b79f19c2bf9b2a0083

HTH,

-- 
-Dave



More information about the swift-users mailing list