Tech —

Learning to code as a 30-year-old kid with Apple’s Swift Playgrounds

A guided tour of the app and a chat with the team at Apple about its goals.

If you've installed the iOS 10 public beta since it came out last week, you’ll know that compatible iPads come loaded with the “Swift Playgrounds” app that Apple announced at WWDC.

The app is Apple’s first crack at anything that even resembles an iOS-native development environment—iPad hardware is now fast enough (and Swift is now stable and mature enough) to make such a tool palatable. But while Swift Playgrounds uses and executes actual Swift code, it’s not going to let you make actual apps. Its aim is educational, specifically for younger kids who are familiar with and comfortable around technology but who have never been exposed to coding before.

I played with the app for a few hours, working my way through the first few tutorials in the public beta—I’m a little older than the intended age group, but I still managed to learn a few things. I also spoke with the team at Apple to learn more about their goals and intentions when they designed the app and to learn how it will continue to develop throughout the public beta process up to the release of the iOS 10 Golden Master.

System requirements and performance

Swift Playgrounds runs on just about every iPad that runs iOS 10, with the exception of the 4th-generation iPad (the one 32-bit tablet left on the current support list). The compatibility list, in full:

  • iPad Air and Air 2
  • iPad Mini 2, 3, and 4
  • Both iPad Pros.

I played with the app on a 9.7-inch iPad Pro and an iPad Mini 2, so I’ve got a pretty good idea of how it runs on the fastest and slowest supported hardware. Load times on the iPad Pro were mostly instantaneous; I didn’t have to wait long for graphics to render or for code to execute, and graphics are sharp and crisp. On the iPad Mini 2, it takes quite a bit longer for things to load, and the 3D graphics look lower-resolution and more aliased.

Once you’re up and running, the lessons are identical no matter which tablet you’re using, but the difference between a newer, faster iPad and an older model is more pronounced than it is in most apps.

The user interface: Touch-optimized coding

The real meat of Swift Playgrounds right now is all in Lesson One, which takes the gamification approach to teaching. The right side of the app is a simple game in which a blobby alien named Byte trundles around an isometric 3D map collecting gems and activating switches. The left side is effectively the game’s “controller,” but instead of buttons or swipes you type in code. And while you can use Swift Playgrounds entirely with the keyboard if you want, Apple has done a lot to make coding less laborious on a touchscreen device.

"It’s an environment designed for touch," Wiley Hodges, Apple's Director of Tools and Technologies Product Marketing, told Ars. "You actually touch code, you actually interact with code. When you’re using 'a' for loop, you’re dragging the loop around the code that is inside it. You get a unique iPad coding experience."

The app is probably best used with an actual physical keyboard, whether it’s a Smart Keyboard cover or something paired via Bluetooth, but Apple has made a few tweaks to the standard iOS software keyboard to make it more code-friendly. Every key has one or two alternate characters that you swipe to type. Swipe the keys in different directions to type with these alternate characters—swipe down from the top or diagonally from the upper-left and right corners depending on where the character is, and you’ll type it without having to go to the Shift key.

By far the most useful text-input features are the suggestions that pop up above the keyboard (or at the bottom of the screen if you have a physical keyboard attached). These suggestions, which unlike standard typing suggestions can be scrolled through horizontally to uncover more, let you quickly and easily tap out certain commands and functions so that you don’t need to worry about repeatedly typing them.

This is especially helpful early on when you’re learning how to code things, but you haven’t yet been instructed on the nuances of Swift’s syntax; some things have parentheses and braces before or after or surrounding them, but you’re not told why right off the bat. A “code library” of keywords like “let” and “for” and “while” and “func” provides an easy reference for a little later on when you’re creating your own code rather than editing existing code, and you can tap and drag any of these keywords to drop them right where you want them. This also applies when you’re debugging and need to move things around or when you’re expanding braces to encompass more lines of code—you can copy and paste like you normally might, but you can also tap and drag.

Finally, Apple includes a series of tools to make referencing basic information and sharing your coding efforts relatively easy. There’s a glossary of terms available for when you need to look things up and options to record movies or (with the help of compatible third-party apps) broadcast live, which could be especially useful for remote classrooms or sharing one student or teacher’s efforts with the rest of the class.

Swift Playgrounds is also meant to give coders full access to the hardware—all the sensors and camera hardware are available to use, and you can even connect to external accessories through Bluetooth. You can't make App Store apps with it, but you can use it to do a lot of the same things a "real" app would be able to do.

Learning core concepts

The Swift Playgrounds app focuses on teaching new programmers about broad concepts that will apply to any programming language, and Apple thinks that Swift in particular is a good fit for this sort of app because it was designed to be easy to learn and to use.

"From the outset, we wanted Swift to be so approachable that it could actually be your first programming language," Hodges said. "We designed Swift with this idea that it had all the performance and power of a compiled language, which is obviously crucial to doing production code for macOS and iOS, but really importantly we wanted it to have the interactivity and simplicity of a scripting language that people find so very appealing."

As a relatively inexperienced programmer (I can poke around in HTML or CSS, but doing anything more serious is beyond me), I appreciated how gradually and clearly Playgrounds introduced basic concepts like “debugging” and “functions.” And within just a few lessons it drives home one important idea—as any programmer will tell you, there’s rarely just one “right” way to solve a problem, though some ways of doing things are more efficient than others.

The first lesson describes everything that’s going on in clear, concise language and is full of hints meant to help you work through certain concepts if they’re a little too hard. The trick is providing enough help for people who need it without making things too easy for the people who would rather play around and figure it out on their own.

"We want everyone to be able to make it through these lessons even without any guidance, so we kind of hide some of the clues in the hint because we want them to explore the world and try to solve it before they get to the hint," said Tim Triemstra, a member of Apple's developer tools product marketing team. "And then at the end if they absolutely need it, we put the entire solution in the hint, because we don’t want anybody to get stuck. But you can’t copy and paste those hints, you have to actually type them in, because as we all know sometimes just going through the action of typing it in makes it easier for you to remember."

Though the lesson is designed as a “game,” there’s no way to lose per se. You can fail to win, but you’re encouraged to use those failures as learning opportunities. You can jump in and start typing new code even as your previous code is running, and hitting the “run my code” button again will immediately start over from the beginning using your edited code instead of the old stuff (the ability to speed up Byte’s waddling would be nice, but at least his meandering pace makes him easy to follow).

Apple says that while the Swift Playgrounds lessons weren’t planned with any particular regimented programming curriculum in mind, they were tested by actual kids ahead of this preview release to make sure that they could be followed.

"We wanted the app to be able to be flexible enough to really support students who wanted to move quickly, students who wanted to take a little bit more time," Cheryl Thomas, vice president of software engineering operations, told Ars. "That was a core goal for us. And we didn’t want it to be prescriptive and very regimented, so that was something we set out to do from the get-go. We worked closely with different educators and of course with kids, a lot of our own kids, and we got feedback very early on.

"We weren’t initially sure what the response would be from an 8 or 9-year-old, but as it turned out, kids today are super savvy, they’ve been around tech for a long time. And the fact that this was real was so cool to them and that they could take what they were doing and really build on that."

Apple uses a relatively gentle learning curve over the course of the first few tutorials. You start out by typing basic code as instructed or by editing some code that already exists. By the end of the second tutorial (the one about functions), the app gives you free rein to create your own functions and functions composed of other functions, and the training wheels come off gradually enough that it never felt too difficult to jump from one lesson to the next.

Error handling isn't particularly elegant, insofar as it's the only part of the app that doesn't tell you things in plain, easily understood language.
Enlarge / Error handling isn't particularly elegant, insofar as it's the only part of the app that doesn't tell you things in plain, easily understood language.
Andrew Cunningham

Keeping younger users in mind, there were just a couple of places where I thought the app could use some work. Especially in early lessons, it would be nice to see individual lines of code highlighted as they’re executed onscreen, just to really drive home the relationship between what you wrote and what’s happening onscreen (this would become pretty difficult to track once you’re nesting a bunch of functions, but it would be a handy visual aid for beginners).

And while small red dots will appear next to individual lines if you’ve typed the name of a function incorrectly or messed up something about the punctuation, the hints hidden behind those red dots aren’t especially easy to parse. I can figure out what “use of unresolved identifier” means, but it might be harder to understand for a 10-year-old.

And finally, while the app is designed primarily with younger users in mind, this isn’t something you’re going to want to plunk down in front of a kindergartner. Apple uses the actual lingo in all of its lessons and brief tutorial slideshows, and kids will need to have decent vocabulary and reading skills to follow along. A representative sentence: “Here, you’re changing the isActive property of the bluePortal instance to false, which deactivates the portal.”

This is easy enough to follow, but only if you’re a kid who’s comfortable cracking open chapter books—Apple says the curriculum is aimed primarily at middle schoolers.

Future plans and what comes next

By the time the final version of iOS 10 is released this fall, Apple says that the “Learn to Code 2” lessons and more Challenges should be available, and the company plans to continue releasing new Challenges on an ongoing basis to keep people engaged. And not all of the lessons will be quite so straightforward as those in the beta.

"While we have this cool 3D world in Learn to Code 1, Learn to Code 2 will actually expand beyond that," Triemstra said. "There’ll be ideas of showing photos or working with algorithms, and the themes will all be varied so it’s not just the same world. I think that will really show the versatility of the app, that you can work in all kinds of different environments in Learn to Code."

If you’ve already completed all the lessons and played with all the Challenges, though, what’s next? After kids learn the fundamentals of coding and of Swift through this app, the next logical step is to enable them to actually start playing with real apps, right?

Perhaps unsurprisingly, Apple isn’t talking about its future plans for Swift Playgrounds, and while this app seems to lay a whole lot of groundwork for some iPad-compatible version of Xcode, such an app doesn’t yet exist. You’ll still need a full Mac to actually make apps—a significant hardware investment, starting at $500 for a basic monitor-less desktop and $900 for the cheapest laptop, neither of which is particularly well-suited for software development—and upload them to the App Store. And while you can export your playgrounds from the iPad app into Xcode 8 and create new iPad-compatible playgrounds with Xcode, jumping from the Playgrounds app to a full development environment won’t be the easiest transition. But in our call, Apple stressed over and over again that the Playgrounds app was designed to teach kids real Swift code, which will make it easier for them to take concepts they've learned and start using them in Xcode.

"I think a lot of environments are intent on learning try to hide the idea of code, and we embrace it here," Hodges told Ars. "What you’re learning here is something that can grow with whatever you choose to do later."

Swift Playgrounds seems like a promising start—a good way to teach kids and neophytes the basics of coding in general and Swift in particular—but it also seems like just a first step down a path that will eventually lead to iOS apps being developed on iOS devices. Even if you never think you’ll use it, it’s worth keeping an eye on. It's even worth trying if you’re not a kid—you might just learn something.

Listing image by Andrew Cunningham

Channel Ars Technica