Learning Swift by building a game (lessons learned)
A few months ago I decided to learn Swift. I am a designer so I had very limited experience in programming. The idea was to jump into the learning process by building an idea, which I had in my mind.
I wasn’t completely new to programming. Ten years ago I did a few courses at the University. I also used to do some html/css, which, of course, could not be seriously considered as coding. Except may be the moments I was shouting “Why this shit doesn’t work, as it supposed to!”
Last 2 years I was constantly playing with an idea of learning programming. But I didn’t make any actionable steps, because in my head, I was, kind of, able to program. It was the unconscious belief, which has broken down one day, when I tried to change the simple javascript function. I failed and it reduced my expectations. From that moment I’ve accepted the fact that I have to spend time to learn how to code.
I chose an iPhone app development course, video lectures from Stanford University. I did it for a couple of weeks, diligently doing every homework. I even made (or better to say copy from professor) the card game. But to be honest, if I need to build something after this course, I would not be able to do it. While I was busy with a course, Apple has presented Swift. I love the simplicity of the language, and I decided to jump into it and build a simple casual game, which I had in my mind. It turned to be a very efficient approach. Partly because Swift is really awesome, partly because you are getting into the flow once you see your idea is taking a shape. Here there are a few lessons I’ve learned on the road:
Copy-paste works great to get started
I started to copy-pasting code and then tweaking it to get results look more what I have in my head. In the beginning, it works really well. I searched “how to ___”, found the answer on StackOverflow and implemented it into the project. But at a certain point when you have to change something more serious, you realized that you don’t understand how the code you wrote actually works. That was the first barrier.
“Where does it come from” principle
Luckily I have a very good technical cofounder who has recommended me to “always think where objects are created”. This was really helpful advice. It did not give me super power straight forward, but it was a simple key to change my behavior. Now when I was blocked I started looking at the code and saw where each spaghetti is coming from.
Brain needs time to digest programming concepts
When my ability to read code was good enough, I was able to distinguish syntax which I do not understand. The pure idea behind certain programming concepts was easy to get. But when I was putting eyes back to a screen I couldn’t connect the abstract idea in my mind with a particular line of code. It is painful! The good thing is that the next time I was dealing with this code I was able to understand it and apply it. Somehow my brain needs time (or sleep maybe) to digest the concept and connect it with a code representation.
Know how to debug helps a lot
Probably it sounds obvious for mature developers, but for my virgin programmer’s brain debug was pretty much an abstract concept. But once I started using it, Swift has turned from unpredictable black box to the black box I could learn. And this was the moment when my learning really started. Now I was able to play with Swift and find how things work.
Get an expert developer to consult with
Another very helpful thing is to find an experienced developer to ask him stupid questions, a lot of stupid questions. In my case it was my cofounder. He helped me every time when I was stuck and don’t know what to try next.
If you don’t have a mature developer, whom you can comfortably disturb with thousands of questions, there are plenty of services like Codementor, where you can find one.
Details eat 80% of the time
I’ve built the first prototype of the game in just two days, with no experience in Swift. And it was an almost complete game with working mechanics and even scores. But it was not fun to play and has a lot disturbing stuff. I started tweaking things to make a game nicer. I made swipes feel better, game experience smoother, added sounds, tested it with users and started the process all over. And there is nothing wrong with this process, just keep it in mind when you’ve built the first version and it feels like 80% of the project is done.
Building a game is not the best way to learn how to make apps
Probably it sounds obvious, but I figured it out only when I switched from developing the game to developing an app. For the game I used SpriteKit when for the app I have to deal with totally different concepts and templates. Even so the syntax is the same approaches are very much different.
Check the game
Summing up, I liked the process of learning programming by doing something I have in my mind. I love the result as well. Actually, I got addicted to the game. Every time I need to test it, I was engaged and played hard to get the best score. I would love to hear your feedback about the game. By the way, my personal record is 2926 ☺