Computer code is very important. Almost every electronic device you use relies on code. The way things work can seem quite confusing, but when you break it down it’s actually simple.
People who make code are called programmers, coders or developers. They all work with computers to create websites, apps, and even games! Today you’ll learn what code it, what it is for, and how to start learning code yourself.
What Is Code?
Computers have their own language called Machine Code which tells them what to do. As you can see, it doesn’t make a lot of sense to humans!
Each number or letter is telling the computer to change something in its memory. This could be a number or word, or a little part of a picture or video. By themselves, computers don’t know how to do anything. It is the job of the programmer to give them instructions.
It is possible to learn Machine Code, but it would take a long time! Luckily there is an easier way to communicate with computers.
What Is a Programming Language?
Now, this looks a little easier to understand! This picture shows how to tell the computer to say Hello, world. Instead of using machine code, it uses a programming language called Python.
Almost all programming languages work the same way:
- You write code to tell it what to do: print(“Hello, world”).
- The code is compiled, which turns it into machine code the computer can understand.
- The computer executes the code, and writes Hello, world back to us.
There are hundreds of different programming languages which can seem confusing, but they all do the same thing. You type in what you want it to do, the compiler turns it into language the computer understands, then the computer does it, which is called executing the code in programming speak!
What Is Coding?
Coding is the process of using a programming language to get a computer to behave how you want it to. Every line of code tells the computer to do something, and a document full of lines of code is called a script.
Each script is designed to carry out a job. This job might be to take an image and change its size. It might play a certain sound or piece of music. When you click like on someone’s post on social media, a script is what makes it happen.
Unlike people, computers will do exactly what you tell them to. This might sound great, but it can cause problems. If you tell a computer to start counting upwards, and don’t tell it to stop, it’ll keep counting forever! Being a good programmer is all about knowing how to tell a computer to act.
What Is a Program?
Scripts by themselves can only do things if they are compiled and then executed. This is useful while you are still working on it, but when you are done, you want people who aren’t programmers to be able to use your script. What you need is to turn your script into a program.
When you are happy with your script, you can compile it into a program. As you already know, compiling changes the code from your programming language into machine code the computer can understand. This time, the machine code is stored in a program which anyone can download and use. Every kind of app, game, or website is a program.
Is Coding Hard?
Coding can be very simple, and anyone can learn the basics. A good analogy is to think of coding like books in a library. Some books use simple language, and the stories are easy to understand. Others use very complex words and have stories that seem to make no sense. Whether they are simple or hard to read, they are all books.
The more books you read, the better you get at it. The complicated language or confusing stories get easier to understand until one day you can read things that you wouldn’t even dream of in the past!
Learning to code is the same. The first time you try to code you will find it hard, but every time you do it you get better. If you find learning a programming language hard, you can still learn the important ideas behind it using a visual coding language.
What Does Code Look Like?
The image above shows a script called hello_name. You’ve already seen that a single line of code can make the computer print to the screen. Let’s say that instead of just saying hello world, you want the user to type in their name, and for the computer to greet them by name? Let’s break down what is happening here.
- When the script starts the computer prints a question to the screen.
- Next the computer waits for the user to input their name, and saves it.
- “Hello” prints to the screen, along with the saved name.
- In the Cmder window, the script compiles and executes using Python.
- The script ran just the way it was designed to, before exiting.
This example shows you a simple piece of code written in a code editor, and run in Cmder which is a type of terminal window. Don’t worry too much about what either of these things is for now. You now know what Python code looks like and how this script works.
How Code Becomes a Program
If you are totally new to code, you might still wonder how scripts like the one above become the kind of programs you are used to using. In the image above, the window on the left is a tool to turn Python scripts into programs. The window on the right has an icon called hello_name.exe. I think you can guess what happens if you were to click on it!
From no code, to a finished program. This example is really simple, but this is how almost all coding works. Every day, people use programming languages they have learned, to write scripts, which will become programs we all use.
credits to makeuseof.com