• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: swift and objective-c
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: swift and objective-c


  • Subject: Re: swift and objective-c
  • From: Ron Hunsinger <email@hidden>
  • Date: Thu, 05 Jun 2014 13:09:48 -0700


On Jun 5, 2014, at 12:07 AM, Chris Lattner <email@hidden> wrote:


On Jun 3, 2014, at 8:19 PM, Jens Alfke <email@hidden> wrote:


On Jun 3, 2014, at 2:16 PM, Ron Hunsinger <email@hidden> wrote:

- In Swift, a..b includes a and excludes b; a...b includes both endpoints.
- In Ruby, it's exactly the opposite. a..b includes both endpoints; a...b excludes b.

Oh, weird. I remembered the Ruby range operators when I read about Swift’s and assumed Ruby was the inspiration; but then why do them the other way around?

(But to me, it makes more sense that three dots would give you a bigger range than two dots. Shrug.)

The Swift approach is easy to remember: one more dot gives you one more value.

A mnemonic like this is useless unless it always leads to the correct answer.

I'm writing some code. I need one of the range operators. I know whether I want the last value to be included, but do I use two dots or three? There's this mnemonic that tells me, but is this the language where that mnemonic works?

And that's the real heart of the problem. I have this mnemonic. It works in Ruby, but not in Swift. Or is it the other way around? I need yet another mnemonic to remind me which language the first mnemonic works in.

The .. operator to create a range first appeared (IIRC) in Pascal, where it could be used to express a subtype of an enumeration. (Integer types are technically an enumeration, as is something like (sun, mon, tue, wed, thu, fri, sat).) If .. omitted either endpoint, you could not write a sub-range that included that endpoint of the underlying type.

Ruby has a .. operator. For consistency with Pascal, .. has the same meaning in Ruby as in Pascal. A half-open range is also useful, especially when iterating over an array or slicing a string, so Ruby introduces a new ... operator for this new semantic.

The question isn't whether more dots should include more values. The question is whether to confuse programmers who routinely work with more than one language. Reversing the meanings does that. It's a bad idea, no matter how well-intentioned.

-Ron Hunsinger

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >swift and objective-c (From: "McLaughlin, Michael P." <email@hidden>)
 >Re: swift and objective-c (From: Roland King <email@hidden>)
 >Re: swift and objective-c (From: Ron Hunsinger <email@hidden>)
 >Re: swift and objective-c (From: Jens Alfke <email@hidden>)
 >Re: swift and objective-c (From: Chris Lattner <email@hidden>)

  • Prev by Date: Re: swift and objective-c
  • Next by Date: Re: Swift
  • Previous by thread: Re: swift and objective-c
  • Next by thread: Re: swift and objective-c
  • Index(es):
    • Date
    • Thread