What is Programming?
Tags: codenewbie, python
Published: 2020-05-19 14:27:00

*by [Rafay Syed](https://twitter.com/retr0rafay)*

Programming is a way for us to give instructions to a computer. The code behind the computer runs everything that you do, from moving the cursor to watching videos to playing video games. It’s a neat way of telling the computer exactly what you want to do since computers will run the instructions you give them without questioning it (unless SkyNet takes over the world). But here’s the thing: computers don’t understand English, or any other human language. Computers speak in binary, meaning in 1’s and 0’s. Does that mean we have to speak to computers in 1’s and 0’s? Just imagine having to learn how to communicate in binary. It would be so hard for schools to teach and it would be tough for students to grasp.

This is why we have programming languages. There are two types of programming languages: high-level languages and low-level languages. High-level languages are languages such as Java, Python, JavaScript, and C#. These languages are closer to the English language and easy for humans to learn and understand. An example of a low-level language is Assembly, which is closer to machine code. If you’re a computer science major, you may have learned about the Assembly language in a Sparc Architecture class. It’s not a language that many employers ever ask for, nor will you ever have to use it, but it’s good to know about it.

Now you may be thinking, if computers speak in binary and we use a language closer to the English language such as Python, how will computers understand what we are trying to tell them? Let me ask you a question. When you try communicating with someone who speaks a different language, how do you overcome that communication gap? Do you use a dictionary, Google Translate, or a human translator? The concept of having a translator is the same with these high-level programming languages! You have a translator that communicates between what the human has typed in the code file and then have that file translated in a way for the computer to understand. The code file gets converted into a binary file known as the bytecode. There are two types of translators: interpreters and compilers. Interpreters go line-by-line, executing each line to the computer. Compilers differ from interpreters since they read the entire file and then translate it. They don’t go line by line and then translate. It’s like saying that a translator wants to know everything you’re going to say to someone, and another translator may prefer that you say one line, have the translator translate that line, and then you continue to say the next line and have the translator translate the next line.

Let’s use Python as an example for illustrating what happens underneath the hood when you run your Python program. When you run the file, it’s given to the interpreter called CPython which goes line-by-line and creates a bytecode file. The bytecode file is then run on the CPython virtual machine, and then you obtain the output from the program on your computer! I know this is a lot of information knowing what happens underneath the hood, and you will probably never be asked this type of question in an interview, but it is good to understand what’s happening when we run our programs.

You may be wondering what the CPython virtual machine is. It’s part of the translator package we install on our computers when we want to run Python programs. It comes with an interpreter written in C (CPython) and it comes with the CPython VM. Now Java runs its programs using a compiler and not an interpreter, which translates the whole file and then creates a bytecode file. The translator you get depends on the programming language.

If you’re new to programming you may be wondering why there are so many programming languages. Why don’t we have one language that can do everything rather than having so many different languages? That is not possible, since each language is used for different purposes. For example, when making video games, C++ is used with the Unreal Engine. With automation, machine learning, AI and data science, Python is used. We also have so many different devices that do so many different things, so it would not be possible to have one language that can encompass every device there is on this planet. Apple uses Swift, while Android uses Kotlin. When you are thinking about what language you want to use or learn, think about what you want to work on. Are you wanting to build an AI chat bot? Use Python. Are you wanting to build a game such as Flappy Bird on the iPhone? Use Swift. It all depends on what you want to work on. When you learn one language, it will become easier to learn the others since the principles are just about the same. Even when you do a coding interview, 9 times out of 10 you’ll be asked to solve a problem in any language that you would like to use, making it a more comfortable experience. Interviewers like to see if you are able to communicate your thought process effectively and explain the steps you are taking in solving a problem. You can always catch up on learning the language that the hiring team uses. But as long as you know your fundamentals, you will be a quick learner in other languages.

And that’s the world of programming! I know this is a lot of information, but it will definitely make sense as you think about it. Just know that programming is the basis of how everything works on your phone, your computer and even your video game consoles.