Think first, then code — A journey through the computational thinking

Girolamo Pinto
Apple Developer Academy | Federico II
10 min readApr 21, 2020

Once someone said : “Think twice, code once.” and he/she was really right.

It’s funny to think about how many times we face to a problem and hardly try to solve it out without success. Often it’s just bad luck or simply we didn’t receive yet the inspiration. But in many cases we don’t have a method, a recipe that helps us to go forward during the creation process.

There are a lot of process that you can follow to reach your goal, but today we want to talk about a process that can improve your coding skills in a very easy way : Computational Thinking.

But let’s proceed in small steps. First of all we present ourselves. We are Girolamo Pinto and Valentino Palomba, we’re two Apple Developer Academy’ students, we are enrolled in university, respectively Computer Engineering and Computer Science, and today we’re going to share with the world our experience about this beautiful method and how we explained it to people during a conference. We know that there are people out of there that can’t code or maybe they don’t want code and we’re sure that there a lot of reason on it. Otherwise we’re 2020 and we think that everyone, from children to adult people, should know to code. And with this method people who never faced this world can now begin to practice code in a property way.

Valentino Palomba and Girolamo Pinto (in this way you know who we are)

What is Computational Thinking?

Well let’s begin with two guys who were proposed to take a conference and they accepted without knowing what to expect. We passed an entire week to prepare the conference, to create an engaging speech because, let’s face it, it’s a boring topic. Also if we think about Ernest Rutherford’s quote : “It should be possible to explain the laws of physics to a barmaid”, it becomes very hard to prepare a speech. In your mind starts flowing such questions as like as : “If people start yawning?” or “If they leave their seat?”. I’m 24 yers old and Valentino is 19 years old and it was our first experience about this kind of stuff. So we decided to give some technical definitions with some jokes.

Passed a week we were on the stage, with a mic in one hand, a clicker in the other and our heads full of monkeys that were playing music cymbals.

The very important question during a presentation, or during a story is : “What is the message that you want give people?”. Well we started from a simple idea : Coding is more than write code. And this sentence should be printed on people’s mind every time they start “writing” code. But why this is so important?

Let’s focus on yourself. You have an idea for a new beautiful app and you want to develop it. So you start to create a simple sketch drawing the interface, focusing on the app’s concept, modelling an UI (User Interface) and an UX (User Experience). Then you open your IDE (Integrated Development Environment) for example Xcode or Eclipse and you start to implementing your idea. You follow a lot of tutorials on YouTube (indian guys’ tutorial are the best), you read a lot of stuff on Stack-Overflow and as like as a machine you copy/paste chunks of code. And then?

Error

An error occurs! Why it happened? Maybe it’s not your fault, or better maybe you made some code mistakes, but why you made it? I think that I know the answer. You didn’t follow a method that helps you to go forward. Copy/paste code it isn’t a good solution. Otherwise to follow a method let you go forward during a project with less mistakes than without a method. We can figure it as a recipe, when you make a cake, before starting the creation process, you look for a recipe, some steps that can guide you during the making of. So why we don’t follow any method when we code? Sometimes it’s excitement, sometimes listlessness. But there’s a solution : Computational Thinking.

As Jeannette M. Wing, professor of Computer Science at the University of Columbia, said in 2006 :

Computational thinking is taking an approach to solving problems, designing systems and understanding human behaviour that draws on concepts fundamental to computing.

As you can see she didn’t talk about solving problems in coding, but she used to talk about solving problems, like a general problem. Yes, because Computational Thinking can be applied to any problem and it doesn’t matter if you’re creating a new app, if you want to send shuttles in space or if you want to repair your car’s wheels. You can apply Computational Thinking everywhere and every-time. You can do it applying its easy steps: Decomposition, Abstraction, Pattern Recognition and Algorithm Design. Let’s move on with the first step.

Decomposition

Dou you like cakes? Me and Valentino love cakes. Especially chocolate ones. Well let’s think to a cake, a four floor chocolate cake and imagine that you want to prepare it for your partner. Me and Valentino aren’t good in cooking cakes, but we should learn it. Anyway, we’re not here to explain you how to cook a cake, but to demonstrate you how much is powerful Computational Thinking in every day life. So, come back to our cake. First of all you see a picture of this cake and the first thing that you could think is ‘This cake has four floors, this is too much for me.’ Well with Computational Thinking, the Decomposition part in particular, we can manage this problem in an easy way.

Decomposition is the ability to breaking down a complex problem or system into smaller, more manageable parts. So, instead to think to a four floors cake, it’s a more manageable problem to think to the first floor, then we can pass to second. It’s very important and crucial during our professional life learning to concentrate on small problems to solve bigger problems.

Ok, let’s do some code. Imagine you want to create a small interface without using storyboard, like this :

Coding in one function

Well that’s a lot of stuff. If you decompose the code, you will see something that is much better.

In this way we have everything in order but also we can easily find everything we need just by using the keyboard buttons composition command + Left click to jump to definition of functions. And also you split the tasks and if there’s a bug, you can fix it easily.

A function for every need

Abstraction

About Computational Thinking’ second principle, Abstraction, we can talk for hours. This is also an OOP’s (Object Oriented Programming) principle and it’s used so many times. But we know that there are people who doesn’t know what OOP is. So we’ll explain this principle in a way that everyone can understand.

The Abstraction principle is a way to make problems or systems easier to think about, hiding detail and removing unnecessary complexity. Let’s think about a cake, again. Maybe at the end of this article you will cook a cake using Computational Thinking, or better you will use it in your everyday life.

Anyway, keep in mind you cake. This time we’re not concentrating on a particular cake (a chocolate one, a three floor one or a seven floor one), but we’ll take a cake in general. So, how can we apply the abstraction principle? First, if we want to cook a cake, maybe we need a recipe, i.e. some steps to follow to create our cake. But in recipes we can find also the ingredients to cook our cake, like milk, eggs etc. Well start from the ingredients that you need, then you pass through the preparation of tools that you need and last but not least you follow the steps to mix your ingredients and create your cake.

Let’s imagine that for your app’s interface you need a button. So the first thing you do is to create a variable var, you can call it button (such a fantasy) of type UIButton.

Well UIButton it’s the easiest abstraction example. Swift provided us huge classes that we can reuse every time we need them, by creating instances of that class.

Pattern Recognition

Have you ever heard about Fibonacci’ sequence? If not, well we’ll let here a link where you can read about it, but after that come back to this article.

Well, for those who know Fibonacci’ sequence, let’s think about it : what you can understand about it? No, they’re not just numbers without meaning. It’s a numbers sequence where each number in the sequence is the sum of the two numbers that precede it. So you can recognise a pattern, a particular way in which something is done or organized, or in which something happens. Understood? No? Ok, let’s come back in kitchen and look at the image that we chosen for you.

Three different types of cake (images taken from Internet)

What can you see? Three cakes. Three chocolate cakes. Three chocolate cakes with a round shape. So we can see that there are some things that are in common, in fact pattern recognition is the ability of recognising shared characteristics between ideas and objects. So the next time you want to solve a problem, you can look up for other problems with same features and you can find a solution easier. And if this isn’t enough, if you decomposed a problem, maybe you can find smaller problems with same features and finding a solution to one of them, it’s like you found a solution to your other problems, cool.

Algorithm Design

At least we have the algorithm design part. Ok, no fear, we will use again kitchen metaphor to explain this part. First of all let’s explain what is an algorithm.

In its purest sense, an algorithm is a mathematical process to solve a problem using a finite number of steps. So it’s just like a recipe, a finite number of step that you can follow to mix in a property way your ingredients to cook your special cake. In fact the algorithm design is a way of getting to a solution through the clear definition of the steps needed.

Nothing happens by magic.

But how you can design your own algorithm? Well you can proceed just like me and Valentino that, in the following pic, we’ll present you a chunk of code that we designed to show you how computers work.

Functions to mix ingredients in Swift 4 applying computational thinking

Alternatively, if you are not so crazy, you can take a cake’s recipe and you can look at the steps needed to cook a cake. Well that is an algorithm and this is the method that we suggested to people who were listening to us during the conference. We asked them to pick up their phones and to write on Notes app the exact steps needed to make a jelly peanut butter sandwich. Me and Valentino would follow exactly what they written on their phones, just like robots.

Before the conference we prepared a table with all the ingredients and we gave three minutes to people to write their algorithm on their phones. After that we asked them to explain how me and Valentino should prepare the sandwiches reading what they written. It was a mess, but it was very funny. We will put some images about that to show you what happened.

Conclusions

It was an awesome experience. We learned how to speak to people who doesn’t know what is programming. But the very important thing it was that we experienced a lot with computational thinking and we applied it in many other projects that we made. After all as Latins used to say :

Docendo discimus

literally “Teaching we learn.” or “The best way to learn something is to teach it.

Obviously Computational Thinking it’s not the one and best method you can follow to solve a problem or to create something. Me and Valentino are experiencing another process to learn how to be good developers: the CBL (Challenge Based Learning) process. It’s another way to approach to problems and to find solutions to them.

As Apple Developer Academy students we’re glad about the opportunity we got and as guys who love this kind of stuff we hope that this is article could be very useful for people who never coded before and they want to begin it, but also for people who are experienced in this field and want to improve their coding skills. Remember that every time you code something, you’re not just a programmer, you’re not just a designer, you’re a creator, an innovator, a problem solver.

You’re a developer.

This is a GitHub repository to begin with computational thinking. It’s a playground file that you can use and re-use every time you want. Good work!

--

--

Apple Developer Academy | Federico II
Apple Developer Academy | Federico II

Published in Apple Developer Academy | Federico II

The Apple Developer Academy is a partnership between the University of Napoli Federico II and Apple. https://www.developeracademy.unina.it

Girolamo Pinto
Girolamo Pinto

Written by Girolamo Pinto

Computer Engineer student. Python developer. C# and Unity addicted. Music, food and Formula 1 lover.