Introduction

This is the third article in our series “Understanding Computer Fundamentals” where we learn about the fundamentals that everyone who works with computers should know. In the previous article, we covered the basics of computer software and operating systems.

In this article, we will cover all the fundamentals of programming in simple and easy-to-understand terms. We'll cover what is programming, how to tell the computer to do what you want, the importance of programming, programming languages and their differences.

This article is not to convince you to become a programmer, but to give you enough knowledge so that you can make informed decisions in the field of technology. So, if you’re new to coding or need a refresher, don’t worry, we will break down the fundamentals of programming in a simple way that anyone can understand.

By the end of this article, you should have a basic understanding of programming and be able to start exploring it on your own. You might even discover a new passion, like I did when I've started learning how to code.

Whether you want to uncover the secrets of the universe, or you just want to pursue a career in the 21st century, basic computer programming is an essential skill to learn.

Stephen Hawking, a legendary physicist and one of the greatest scientific minds of our time
Stephen Hawking

What is programming?

Before we go deep into the fundamentals of programming, let's define what programming actually is. There are many definitions of programming that I've found, but in simple terms, programming is the process of creating instructions for a computer to follow.

These instructions are known as code, and they are written in programming languages. We will go more into programming languages in a few minutes, but essentially, these languages allow us to communicate with computers and tell them what to do.

The same way a trainer gives instructions to athletes on what exercises to do, programmers give instructions to computers on what tasks to perform.

Trainer is giving the instructions to children is an analogy to programmers giving the instructions to computers.
Trainer is giving the instructions to children is an analogy to programmers giving the instructions to computers.

The only difference in this analogy is that athletes can misinterpret or ignore the trainer's instructions, while computers will do exactly what they are told to do. The only time when a computer can misinterpret or ignore instructions is when there is a mistake in the code.

Why is programming important?

Programming is the backbone of modern technology. Every piece of software, from mobile apps to desktop applications to websites, is created using programming languages. Programming allows creating programs that could automate boring and tedious tasks that humans had to deal with, like sorting through large amounts of data or performing complex calculations. Why would someone want to count all the characters in a novel, when they can use a program to do it for them? There is so much value in things like computed tomography, automated manufacturing systems, and even self-driving cars that would not be possible without programming.

A person is prepared to be scanned using a computed tomography (CT) scan machine.
A person is prepared to be scanned using a computed tomography (CT) scan machine.

Imagine sending your friend a physical letter instead of a message in your favorite messenger app. Programming is what makes that messenger app possible, and it's also what enables communication between different types of hardware and software.

In short, programming plays a crucial role in the development and advancement of technology, and it has become an essential skill in the 21st century. It helps people to solve complex problems that we may face in our daily lives, like organizing and analyzing data, automating tasks, creating new technologies or improving existing ones.

Programming languages

There are many programming languages available, each with its own way of writing (syntax) and use cases. Just like spoken languages, programming languages have rules and syntax that must be followed for the computer to understand them. Some popular programming languages include JavaScript, Java, C, C++, C#, Python, PHP, Ruby, Swift, SQL, TypeScript, Go, Rust, and more. Each programming language has a logo, documentation, and a community that supports it, which can make it easier to learn and use.

Logos of some of the most used programming languages in the world.
Logos of some of the most used programming languages in the world

We have so many programming languages because different tasks require different languages. For example, PHP and JavaScript are commonly used for web development, while C++ and C are often used for programs that require high performance. C# and C++ are popular for game development, while Python is excellent for data analysis and machine learning.

Programming languages are created not for computers, but for humans to share and maintain programs. The CPU of the computer only understands machine code, which is represented in binary digits (0's and 1's).

We'll discuss machine code later in this article, for now, just remember that programming languages need to be translated into machine code for the computer to execute them. Just like we need to translate languages when we travel to a foreign country.

Learning a programming language can seem daunting at first, but in reality, once you know at least one language, learning others becomes easier. It's like learning how to drive a car, once you learn it, you can apply those skills to drive any other car brand.

Programming languages can be learned through learning platforms like Udemy, Pluralsight, or services like Codecademy, Educative and others. It's important to find the resources that work best for you and your learning style.

Codecademy - Develop yourself

In conclusion, programming is a crucial skill that can open up many opportunities in the technology industry. By breaking down programming into its fundamental concepts and learning at least one programming language. You can begin developing your own applications, automating tasks, analyzing and organizing data, creating websites and more.

Essential Concepts

Whether you want to start programming or just want to know how programming works, there are a few essential concepts that you need to understand. There are many concepts to consider, but we will cover some of the most significant ones.

Here are five of the most basic concepts of programming:

  1. Variables: These are placeholders that store values, such as numbers or text, that can be used in a program.
  2. Constants: The same as variables, but these values cannot be changed once they are assigned.
  3. Data types: These are the different kinds of data that can be used in a program, such as integers, strings, and booleans.
  4. Conditions: These are the building blocks of programming logic, and include conditional statements (if/else). We use conditions to make decisions in our code based on certain criteria.
  5. Functions: These are blocks of code that can be reused throughout a program, and can take inputs and return outputs.
JavaScript code on the monitor's screen
JavaScript code on the monitor's screen

If you have ever seen how code looks in editors, you may have noticed that it has different colors. Code editors highlight code in different colors to make it easier for programmers to read and understand their code. Each color represents a different element of the programming language, such as keywords, comments, variables, or strings. This visual separation allows programmers to quickly identify different parts of their code and helps them catch syntax errors or other mistakes.

These concepts are the building blocks of programming and are used in almost every programming language. It's like building materials that programmers use to create applications, websites and more.

I will go through each of these concepts briefly to give you an idea of what they are and how they work. Don't worry if you don't know anything about these yet, we'll break them down in a simple way that anyone can understand.

Since there are a lot of programming languages, our examples will be written in a programming language called TypeScript, since it's one of the most popular languages and the one I know pretty good. Normally, I would give examples in JavaScript, but since TypeScript is a better version of JavaScript, it will help you understand types and other concepts that JavaScript is terrible at. So, let's dive into these essential concepts of programming and get started!

1. Variables

Variables are like containers that hold information or data within a program. You can think of it like a cookie jar, where you can put in different sweets, like candies or cookies. In programming, you can put different kinds of information in a variable, like numbers or words. Here is the example of putting a word “Serhii” in a variable named myName:

let myName = 'Serhii'

The keyword “let” means that we are creating a variable and giving it a name, which is myName in this case. Once you put something in a variable, you can use it in your program later on.

It's called a “variable” because the information inside it can change, similarly to the things you put in a jar can be different every time. This is how I would change the information in myName the ⁣ variable to something else:

let myName = 'Serhii'
myName = 'John'

Now, the myName variable contains the value “John” instead of “Serhii”. A common question that people ask is why do we need to put values in variables? Can we just use the values directly in the program? The answer is pretty simple — in almost all cases, you don't know what the value will be.

Variable definition explained

As someone who writes a program, you don't know what the user is going to type in the form field. That's why you have a variable, it holds whatever value the user types in, and you can then use it throughout the program.

The only thing that we know for sure is the type of data we are expecting. Let's talk about data types now.

2. Constants

Constants are pretty easy to understand once you know what the variable is. A constant is similar to a variable, but its value cannot be changed once it's defined. In TypeScript, if we want to tell a computer that we create a constant, we use the keyword “const”.

const taxInUkraine = 0.05

We use constants only when we know for sure that we don't want the value to change throughout the program. If you try to reassign a value to a constant, you'll get an error.

3. Data types

Similar to how there are different types of toys, such as dolls, cars, and building blocks, in programming, there are different data types, such as numbers, strings, and booleans.

Similar to how you can't put a toy car into a dollhouse, you can't mix data types in programming. For example, you can't add the word “hello” to the number 5, just like you can't put a toy car inside a dollhouse meant for dolls.

In the previous example, we had a variable named myName that held a word “Serhii”, which is an example of string data type.

Data types can vary depending on the programming language, but in TypeScript (our example language), some common data types include:

Numbers

This data type includes any numerical value, whether it's an integer number or a decimal number. Number 3 and 5.2 are examples of number types. We can declare (create) a variable with a number like this:

let age = 33

Strings

This data type includes any text value, such as names or sentences. It's surrounded by single or double quotes to make it clear where the string starts and ends. We must wrap every string with single or double quotes to tell the computer that it's a string, and otherwise, it will think it's some variable name or a function.

For example, we can have a variable called famousQuote that holds a string value like this:

let famousQuote = "I have nothing to declare except my genius. - Oscar Wilde"

In JavaScript and TypeScript, we can also use backticks to write strings like this: `This is my string`. Other programming languages don't have that.

Booleans

This data type has only two values – true or false, and is often used in conditions and comparisons. It's used for expressing truth values, such as buttons that can be turned on (true) or turned off (false).

For example, we can have a variable named isRaining, which is a boolean type that holds the value true if it's raining outside and false otherwise.

let isRaining = false

Later in our code, we can use the isRaining variable in conditions to make decisions. We'll dive into conditions soon in this article, just remember that booleans are used to express either true or false values in programming and can be helpful for decisions or comparisons.

Objects

This data type is used to group related pieces of information into a single entity related to each other. Imagine you have a backpack where you can store different things, like books, pencils, and snacks.

An object can be like that backpack where you can store different things, but instead of books and pencils, you can store things like the person's name, age, and favorite color.

let user = {
    name: 'Serhii',
    age: 33,
    favColor: 'red',
}

Arrays

This data type is used to store a collection of values, such as a list of names or numbers. An array is like a treasure chest that can hold many things inside it. Each item in the treasure chest is numbered, starting from 0. We usually use arrays when we want to store many related values like posts, comments, or messages.

let comments = [
    "Hi! Thank you for your article",
    "I'm a beginner in programming and I'm trying to learn",
    "Great article! I like it very much",
    "Hey! I'm a beginner in programming and I'm trying to learn",
]

Arrays and Objects are complicated topics for beginners. I will not go into the details of each but remember that objects group related information and arrays group related information. Objects give each piece of information a name, while arrays give each item an index number starting at 0.

4. Functions

Functions in programming are like recipes for the computer. Similar to how your mom follows a recipe to make a cake, a programmer uses a function to make the computer do something specific.

A function is like a cooking recipe. Different recipes have different ingredients and steps to follow to cook a meal. Similarly, functions in programming have different arguments and code inside them that perform a specific task.

For example, if you want to teach the computer to multiply 2 numbers, you can create a function called multiplyNumbers that takes two parameters, multiplies them together, and then returns the result.

function multiplyNumbers(a: number, b: number): number {
    return a * b
}

When your function is defined, you can now use it throughout your program whenever you need to multiply 2 numbers.

const result = multiplyNumbers(2, 3)

Details graph of a function in TypeScript

The result variable in our case will contain the value 6 because when our function is executed, it will take in 2 and 3 as arguments, multiply them together, and return the result of 6.

Functions are a complex topic, it's hard to explain it in just a few sentences, just keep in mind that functions are like recipes for the computer. They allow you to create reusable code to perform specific tasks.

5. Conditions

Conditional statements in programming are like rules that the computer follows to make decisions. Imagine you are building a website, and you want to give your users an ability to switch between dark theme and light theme.

You can write something like this:

if (isDarkTheme) {
    loadDarkThemeStyles()
} else {
    loadLightThemeStyles()
}

If the variable isDarkTheme is true, it will load the dark theme styles, and if it's not true (false), it will load the light theme styles. In other words, if the isDarkTheme variable holds a boolean value true, the computer will run the if block; otherwise it will run the else block.

Showing examples of how code will be executed
With the red color, I'm pointing which line will be ignored.

What is machine code?

To continue with our discussion on programming fundamentals, we have to know what machine code is and how it relates to programming.

Machine code is a low-level representation of the code that can be read and executed by the computer's CPU directly. Programs written in machine code are extremely difficult to read and modify, so most programmers work with programming languages that are easier to understand and write than machine code.

To give you a better understanding how machine code looks, here is an example:

0100110101111001001000000110111001100001011011010110010100100000011010010111001100100000010100110110010101110010011010000110100101101001

If you translate this machine code into human-readable language, it would be “My name is Serhii”. The letter “M” corresponds to the “01001101” and the rest of the letters in the message correspond to their respective binary codes.

The Central Processing Unit (CPU) installed on the computer's motherboard.
The Central Processing Unit (CPU) installed on the computer's motherboard

As you see, it's almost impossible to work directly with machine code. Hence, we use programming languages that are human-readable and allow us to write code more efficiently.

The CPU of the computer can understand only 1s and 0s because it's made of transistors that can have only two states: on or off. A transistor is like a switch that can either let electric current flow or block it.

Compiled and Interpreted Code

To translate our code into machine code that the computer can understand and execute, we use a compiler or interpreter specific to the programming language we're using.

A compiler is a program that translates the source code of a programming language into machine code. It saves this machine code in a separate file, which can be executed later on by the computer's CPU. The most popular compiled programming languages are C, C++ and Go.

3 logos of programming languages: C, C++ and Go

The advantage of using a compiled programming language is that the resulting machine code runs fast because it has already been translated into machine code.

The disadvantage of using a compiled programming language is that the development process can be slower because we have to compile our code every time we make changes.

Everyone should learn how to program a computer because it teaches you how to think

Steve Jobs, co-founder of Apple Inc.
Steve Jobs

An interpreter is a program that reads and executes each line of code directly, without creating a separate machine code file. An interpreter runs our code line by line and shows us the result immediately. The most popular programming languages that use interpreter are PHP, Python, Ruby, and JavaScript.

4 logos of programming languages: PHP, Python, Ruby and JavaScript

The advantage of using an interpreted programming language is that it's easier to write and test code because we can see the immediate results of each line.

The disadvantage of using an interpreted programming language is that the resulting program can be slower compared to a compiled program because it has to be translated into machine code line by line during execution.

Executing code

When the computer executes code, it follows the instructions given to it one by one, from the top to the bottom. This process is called “running the code” and it's how software applications are created.

It is done this way because the program needs to have a logical flow of instructions, and executing them in order ensures that the program operates correctly. Think of it like reading a book from the beginning to the end.

Try to read the code below from top to the bottom and understand what it's doing:

let user = getUserFromDatabase(1)

user.isOnline = true

if (user.isAdmin) {
    redirectToAdminPage()
} else {
    redirectToHomePage()
}

Reading code from top to bottom makes it much simpler and easier to work with.

Choosing a Programming Language

A male with dark hair wearing headphones, loocking into the macbook

If you don't know how to program, choosing a programming language can be a daunting task. Here are some tips to help you pick the right programming language:

  1. Determine your goals: What do you want to achieve with programming? Do you want to build a website, create a mobile app, or develop software for your computer? Different programming languages are better suited for different tasks, so it's important to know your goals before picking a language.
  2. Consider your experience: Have you programmed before? If so, what languages have you used? If you're a beginner, you may want to select a language that is easier to learn and has many resources available to help you.
  3. Experiment: Once you've narrowed down your choices, it's a good idea to experiment with a few different languages to see which one feels the most comfortable and enjoyable for you to work with.
  4. Get advice: Don't be afraid to ask for advice from other programmers, or do research online to find out which languages are popular and trending. Keep in mind that trending languages may not necessarily be the best fit for your goals or experience level, so always consider advice from multiple sources before deciding.
  5. Remember to have fun: Programming can be challenging at times, but it's also a rewarding and enjoyable hobby or career. Programming allows you to be creative and build something from scratch, which can be very satisfying.

Conclusion

In conclusion, programming may seem intimidating at first, but with practice and patience, anyone can learn to code. A basic understanding of programming fundamentals can benefit you in any technical field or career that you may pursue.

We now know that programming is the process of writing instructions for a computer. Without programming, we wouldn't have the technology we have today.

Computers can only read zeros and ones, but programming languages allow us to communicate with computers and create wonderful applications, websites, software, and more. To achieve this, the programming language of our choice needs to be compiled or interpreted into machine code, which the computer can understand and execute.

Green binary code (1s and 0s) zoomed

Programming languages have different uses, strengths, and weaknesses depending on the task at hand. But, there are many things they have in common, like variables, constants, data types, objects, arrays, and control structures like if/else statement.

We've also learned that code executes line by line from the top to the bottom. It's done this way to make sure that the code runs in a logical sequence, and each line builds upon the previous one.

If you have any suggestions or tips for improving this article, please let me know in the comments below. I'll make sure to read and consider all the feedback.

Keywords: software, binary, code, machine, essentials, functions, variables, types, typescript, compile, compiler, interpreter, interpreted, conditions, hawking, jobs