Swift, bad idea #1

Looking over the “Swift” language Apple presented during the WWDC keynote. First off, declarations using “var” and “let” made me think of Basic, and had to stifle a gag reflex.

I’m reading the iBooks book on Swift. When I got to closed and halfopen ranges on page 100, I thought this was a big mistake. It’s very hard to see at a glance which is which. We’ve been trained for so many years to see ranges in for loops as closed, and react immediately if that expected “-1” as in “(0 to n-1)” or equivalent, is missing.

Sure enough, go to page 135 in the same book, and the example given is clearly wrong, where the author of the book confused the two. Two dots is a halfopen interval, three dots a closed interval, and the example is:

“shoppingList[4...6] = ["Bananas", "Apples"]”

(Excerpt From: Apple Inc. “The Swift Programming Language.” iBooks.)

This is not going to end well.

Update: I was wrong. See the comments.

2 thoughts on “Swift, bad idea #1”

  1. I thought that example was actually showing that you could replace an uneven range – may have to go back and double check. I agree with you that that will get confusing, especially since explicitly iterating based on the count is silly these days.

    Most of the language constructs are really nice though – they’ve put real effort in areas where bugs commonly occur. It’s one of the cleaner complied C-style non VM languages I’ve seen to be honest, and it’s very approachable (unlike some languages I enjoy like Scala that really may move a little bit too far towards scripting terseness for a multi-year project with lots of maintenance work)

  2. Richard,

    You’re right. It wasn’t an error in the text, and I was wrong. But I still think the syntax is unnecessarily confusing without any real benefit.

Leave a Reply

Your email address will not be published. Required fields are marked *