A big part of why Swift is an attractive language is Playground. When I first saw Playground during WWDC’s unveiling of Swift, the immediate thought that cross my mind is that Playground is exactly how I program. What I mean is that when I am working on a project and I am not sure how to do a certain task, I would create a new test project to work out ideas or just general exploration to find a way to accomplish what I need to do in code. Sometimes, the solution don’t just arrive after one test project. There’ll be a second, third, and sometimes, many more. Iterate and iterate until I find the solution.
The procedure is such that I create a new project in Xcode. After which, I’d want to say start writing code and on the way to discover the ultimate solution to my problem. However, in reality, this is the point I’ll have to write the view controller, the views and what ever I need to bring it to the point I can start writing test code to even begin testing my ideas. In that way I’ve created and deleted countless test projects. Sometimes, the idea I’m testing requires fewer overhead code to support, while other times, I need to have an extensive setup that takes much longer than I’d like to even get to the point to start write test code.
With Swift and Playground, there are no need to write in complete programs. It’s like Apple was reading my mind when they got the idea to make Playground part of the Xcode suite to go with Swift. It is exactly how I’d write programs but with all the extra overhead taken out. In Apple’s own words:
Experiment with Swift code in an interactive environment known as a playground. Without requiring you to compile and run a complete project, a playground provides quick feedback for the results of your coding experiments. — Apple’s Documentation
I would have describe Playground a godsend!
Granted, you do need to have some setup code if you are trying to test something within something complex like figure out the path of an object in your game scene but all the support code will be in one way or another be directly related to what you are trying to test.
The other reason I brought up playground here is the fact that playground is the perfect tool for learning Swift. You can easily follow along a Swift programming book or an online tutorial on Swift you happen to find. Traditionally, programming books and tutorials are written in such a way that the central subject is precede with supporting code so that the example code presented is a complete program where readers could plug into the IDE for execution. Those supporting code can sometimes be way ahead the central topic at the given point of the text and very confusing for the readers to follow. Most authors would try to quickly brush over them either without much explanation or by writing “don’t worry about this part of the code for now.” I strongly feel that those overhead cruft gets in the way of learning the central topic. Now, with playground, I won’t say it’ll totally get rid of the cruft but at least keep it down to a minimum. I can’t wait to see how playground will transform teaching materials in the coming months.
—Swiftloc signing off.