25 March 2019

What Is Coding and How Does It Work?


whats-coding

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?

Machine Code Example

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?

Hello World in Python
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:

  1. You write code to tell it what to do: print(“Hello, world”).
  2. The code is compiled, which turns it into machine code the computer can understand.
  3. 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?

Sometimes Code is Easy to understand

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?

Code can be like Books in a Library

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. You can even make your own Mario game without typing any code at all!

What Does Code Look Like

Sample Python program

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.

  1. When the script starts the computer prints a question to the screen.
  2. Next the computer waits for the user to input their name, and saves it.
  3. “Hello” prints to the screen, along with the saved name.
  4. In the Cmder window, the script compiles and executes using Python.
  5. 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

Turning a Script into 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!

Gif of the working .EXE file

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.

Coding Is Cool

Today’s article has taught you what code is, and how some Python code works. There are lots of great websites and apps which can help you learn programming too!

Coding is for everyone, and starting has never been easier. You can even learn to code using Minecraft!

Read the full article: What Is Coding and How Does It Work?


Read Full Article

No comments:

Post a Comment