This week, instead of one of the tutorial-type articles I’ve been publishing recently, I’ll go back to basics with an article aimed at those who are new to coding or those who are interested to know more about what this subject really is.
Until relatively recently, coding was a subject reserved for a select few. Today, more and more people use it in one form or another. But, although everyone knows what coding is at a superficial level, not many know what it really is.
In this article, I’ll share the picture I have in mind of how I see coding and how I try to make sense of it as a subject.
A quick note: you may hear of coding and of programming. Are they the same thing? The answer to this question is not that simple. In brief, no and yes. Technically, there’s a difference between the two which I won’t address here–I’ll leave that discussion for a future post. But in most common usage, the two words are used interchangeably, and that’s how I’ll use them in this article.
Coding is a form of communication. Let’s see how humans communicate with each other first. Consider two friends having a conversation:
- One of the friends has thoughts and ideas in his head. He converts these ideas into words and sentences using the vocabulary and grammar of a language that both friends can speak.
- The words travel from one person’s mouth to the other’s ears, and the listener’s brain converts these words back into ideas that she understands.
The process keeps repeating itself. The two friends share their thoughts and ideas by converting them to and from words using a language they both know.
Coding is a very similar process. However, communication is between a human and a computer. The human converts his or her ideas into computer code written in a coding language that the computer “knows”. The computer understands these instructions and performs the tasks it’s being asked to do.
The communication between a human and a computer is more one-sided than when humans communicate with each other. Humans give instructions to the computer and the computer rarely “talks back”. Usually, the computer only “speaks back” to complain when there’s a problem with how the human communicates, which we call errors and bugs in the code.
Don’t I Communicate With Computers Each Time I Use Them?
Not everyone can code, but everyone uses computers. Isn’t this also communicating with a computer, asking it to do stuff for us?
Yes, it is.
But, here’s the difference. When you use a computer as a user, and not as a programmer, you’re using software. You can only ask the computer to perform actions that the software you’re using allows you to use. When you choose an option from a menu or click on a button in software you’re using, the computer will perform specific tasks. But those are the only tasks you can ask the computer to perform. The programmers who wrote the software determined what these tasks are.
A good analogy is that of the Matrix films. When you use a computer, you don’t see the code that’s running out of sight behind the scenes. As a user of the software, you’re unaware of the code that’s running when you click that button or choose an option from a menu. A bit like the people living their lives in the Matrix films, unaware of the matrix!
As a user, you can only ask the computer to do whatever the software allows you to do. You can buy more software, but you’re still limited to whatever software someone else wrote and made available. For many requirements that need a computer, using ready-made software is more than enough.
But, if you need your computer to perform more specific and specialised tasks to meet your exact requirements, you’ll need to be able to speak its language–you need to know how to code.
When you write a computer program, you’re communicating with the computer at a much more basic level than when clicking buttons in ready-made software. You have more granularity and more control over what you can get the computer to do for you. This flexibility comes at a cost. Writing computer code is harder than using software.
Your imagination and your coding skill are the only limits. You can get the computer to do anything you want. Well, almost anything!
Why Can’t I Speak to The Computer in English?
If coding is a form of communication between a human and a computer, why can’t you speak to it in English, German, Mandarin, or any other human language? Why do you need to use a coding language instead?
Although there are many similarities between human-to-human and human-to-computer communication, there are also some very important differences. One of the main differences is the following:
Computers are stupid.
We often think of computers as being “clever”, but it’s the software we use that do clever things. Therefore, it’s the programmers who wrote the software who are clever, not the computer.
When you code, you always need to remember that you’re dealing with a device that is not clever. It’s powerful and fast; it doesn’t get tired, nor does it get bored. But, it’s not clever. Therefore, it’s your job to be clear and unambiguous and follow steps logically and in the correct order.
English and other human languages are languages intended for communication between intelligent beings. We understand the context of what’s being said and, therefore, the human languages have evolved to take our intelligence into account. Coding languages, on the other hand, are designed specifically to communicate with computers that have no intelligence and don’t understand the context of what’s being said.
Comparing communication in English and Python
Here are a couple of examples to show how the way humans communicate is not good enough when communicating with a computer.
Consider you arrive home from running some errands or from work, and your spouse calls out:
“Hello! Dinner is ready in 20 minutes. Can you get the tomatoes ready, please?”
What do you do? You’ll check what dish your spouse is preparing to figure out what you need to do with the tomatoes. You may need to wash them under the tap, chop them finely, and season them with salt and pepper.
Consider now the case when your spouse calls out:
“Hello! Dinner is ready in 20 minutes. Can you get the children ready, please?”
These two phrases are almost identical. The only difference is that the plural noun tomatoes in the first scenario was replaced by another plural noun children in the second. The structure of the sentence and the verbs used are identical. However, your response to the second phrase is not to wash the kids under the tap and season them with salt and pepper, but perhaps to get them to finish their homework and clear the table, say.
Your actions are very different even though the phrases are nearly identical, with the exception of one noun. Your lifetime experience lets you understand that getting something ready can have very different meanings, depending on the context.
Computers cannot do this. They don’t understand context. You’ll need to use different, clear, and unambiguous instructions if you want the computer to do different things.
Here’s another example. You’re told to do the following:
“Say Happy Birthday”
If you’re the obedient type, you’ll speak out the words Happy Birthday.
How about in the following case:
“My name is Stephen. Say my name”
Unless you’re three years old or you’re being deliberately funny, you’re unlikely to speak out the words my name. Instead, you’ll say the name Stephen. However, the phrases Say Happy Birthday and Say my name are very similar. The verb say is followed by two additional words in each case. Humans have no problem understanding that in the second case, you need to replace the placeholder my name with the information that’s been associated with it earlier, in this case, the name Stephen.
A coding language needs to make a clear distinction between these two cases. In Python, you’d write:
my_name = "Stephen" print(my_name)
If you’re not familiar with Python, I’ll leave it as an exercise for you to guess what the role of the speech marks
" " in the above examples is!
What Stuff Can I Ask The Computer To Do With Coding?
So, what things might you want to get a computer to do using coding? The answers to this question are many and varied. A good way of thinking of a computer program is as a tool that can perform actions that you, as a human, would require a lot of time and effort to perform. The computer will perform these tasks much faster and won’t make mistakes (as long as you’ve written the computer program correctly!)
Consider this simulation showing lots of bouncing balls:
How would you create this animation manually? Let’s imagine you’re using a classic flip book animation technique:
- First, you choose how many balls you wish to create and their starting positions and colours.
- You draw them on the first page of your flip book.
- You decide how fast and in which direction each ball is moving.
- Next, you fetch a calculator and work out how much each ball moves in a small span of time. You work this out based on its original speed and direction and the effect of gravity on the ball. You’ll need to calculate this for each ball.
- Now you know where each ball will be a fraction of a second later, you can redraw all the balls in their new positions.
- You’ll also need to decide whether any of the balls has hit the floor or the sides, and if they did you need to take the bounce into account when working out the next location for that ball.
- Keep repeating this process until you’re exhausted or until you’ve run out of pages in your flip book.
Congratulations, you’ve manually created an animation of many bouncing balls. You only need to run this experiment as a thought experiment to know that it involves a lot of work and time and effort, with plenty of chances to make mistakes.
And if you want to create a new simulation with a different number of balls and different starting positions, you’ll have to repeat the whole process all over again.
However, if you give instructions to a computer to perform the tasks shown in the bullet points above, the computer will be able to do all the hard work for you, whenever you want, as often as you want.
If you’re curious as to what the Python code to create this simulation looks like, you can read the blog post about Using Object-Oriented Programming in Python to Simulate Bouncing Balls. Scroll to the bottom if you just want to glance at the completed code!
This is just one example. Most things you can think of, you can write a computer program to do. When beginners start to learn programming and reach some early milestones, one of the biggest revelations they realise is that many things they believed were impossible to do now become possible.
Here are a couple of other examples from recent blog posts:
- Simulating 3D Solar System in Python
- Creating an animation of chaotic balls using lists, tuples, dictionaries, and sets in Python
All these examples are visual, but many programs deal with analysing data and don’t require a visual element.
The ability to ask a computer to perform very specific tasks for you has made coding a key element of most jobs and activities in our modern world. More and more fields have started to rely on coding to analyse the large amounts of data present, to run simulations to explore what would happen in many different scenarios, and more.
As a result, coding is no longer a field for the select few who go on to become professional software developers. Many more people are learning coding as an additional tool in their field of work. Scientists and finance professionals are two such examples that have relied on coding for a long time. But many others are joining in too.
Are you tempted?