/SwiftRockets

Swift Playgrounds book crafted for National Science Week 2020, in which a set of small visual activities teach beginner--intermediate concepts of Swift and the space debris crisis side-by-side.

Primary LanguageSwiftMIT LicenseMIT

SwiftRockets

Swift Rockets is a Swift Playgrounds book crafted for National Science Week 2020, in which a set of small visual activities teach beginner-intermediate concepts of Swift and the space debris crisis side-by-side.

Preview of in-engine assets

The book features 6 Playgrounds pages that each have a functionally standalone activity but that builds upon the lessons of those that came before, with unique hand-drawn art and simple code activities to incrementally teach Swift concepts of increasing difficulty. This begins with a print("Hello World"), goes through variables and types and control logic, gently touches on more intermediate issues such as inheritance and memory management, and ends with an introduction to closures through higher-order functions.

Preview of in-engine assets

Alongside these concepts, a story is also told that goes from posing the challenge of "launching a rocket" to quickly demonstrating that the launching isn't the whole problem.

Screenshot of Playground in action

How to Install

To use a Playgrounds book file, you will need the Playgrounds app. The enclosed file is designed to give the best experience on iPad and iPad Pro. However, this file can also be run on macOS in either the macOS Playgrounds app or in Xcode. The experience should be the same but no guarantees can be made for performance on older hardware.

To install this project, download this repository by clicking the green Code button at the top left, and unzip the file. If you have Git installed, you can also get this project by checking out this repository.

Please keep in mind that these live-coding environments can take a moment to load even on new or expensive devices, and they are performing the extremely resource-intensive task of compiling and running code as you write it. There are several avenues for tech support should you have an issue with the Playgrounds app on any platform, but most of the time you just need to give it a moment 😆

How to Use

Playgrounds is a ground-breaking tool that allows users to skip over the excruciating debugging cycles that once dominated the learning experiences of new programmers. Where once a person would have to write a program, compile it, and run it to see if it crashes so they could fix something, Playgrounds is a live coding environment, sometimes referred to as a REPL.

This means that there is a text area much like in Notepad or your favourite programming IDE, that you can just type code into it and press play. You can run one, or a few, or all lines in a program at once for powerful control of logic and behaviour. It's a perfect learning and teaching environment, but it may take some getting used to.

Here are a few pointers:

  • Firstly, code in Playgrounds is often split up over pages and between bits of text and pictures and it can get a bit confusing. If you're struggling to tell what's code and what's not or keep on track on a page, you can always delete text or copy-paste code around. And just because each page is separate when you run it, doesn't mean you can't go back and copy some code that did something you wanted or that you know works.

  • Secondly, the code you see is not all there is. Playgrounds often rely on code in hidden resource files to power functions such as visualisation that would be too annoying to teach. This means you can write code that breaks something in a way you never could have known and won't be able to find or debug. So just in case you break something bad, it's good to keep a fresh copy of your favourite playgrounds around and have a play with a copy. And there's no shame in downloading from scratch.

  • Thirdly, it does not represent the powerful environments most developers deal with day-to-day. IDEs and code editors--the apps most programmers use to do the majority of their work--come with features such as code completion (like autocorrect for your code) and inbuilt documentation (that tells you what functions everything has and how they work). While Playgrounds does its best at some of these features, don't be disheartened if even as an intermediate programmer you find it hard to do. Nobody expects you to remember how everything works or know how to fix everything that comes up so don't hesitate to make great use of search engines, blogs, books, friends and family.

Looking for More?

There are so many great playgrounds about I couldn't list them all if I tried. But a great place that I go to start looking is uraimo's curated list of awesome Swift playgrounds on GitHub, or you can search the official playgrounds that you can download straight in the app. I've also made another playground like this myself, explaining the basics of procedural terrain generation, that you can find and download here.

And if Swift isn't really your thing but you want to play around more with live coding environments, why not check out some of the ones that have been made for other programming languages? The most popular one is probably Jupyter Notebooks for Python, which you can play with online for free with Google's Colaboratory site.

About the Author

Headshot of author, Mars Buttfield-Addison

Swift and Space Junk might seem a weird combination to pick for a Science Week activity, but it's not as unusual as you may think. In fact, it's what I do.

I'm Mars (yes, really) and I am a PhD Candidate at the University of Tasmania, studying how we can use technologies like we use in self-driving cars to detect and manoeuvre around pedestrians to better detect and track junk in space. My primary tool is Machine Learning/Artificial Intelligence technologies and one of the few ways we can make such things is with... (you guessed it) Swift! I use Swift all the time for everything from prototyping to making apps, and I love it so much I wrote a book about it (and am now writing a second one) 📚👍

So if you have any more questions to ask, want more ideas for things to do with Swift, or just want to chat about junk in space, then get in touch!

--Mars Buttfield-Addison 👩‍💻 Twitter | Email | LinkedIn