What Is Programming? And How Does a Computer Understand Code?

Uploaded Image

Level: Beginner. This is the first lesson in the «Programming from Zero» series. There is no prerequisite — you only need to know how to use a computer and a browser. If this is your first visit to the blog, start with the intro post to see the full lesson map.

This lesson is also available in Arabic: يعني إيه برمجة؟ وإزاي الكمبيوتر بيفهم الكود أصلاً؟

The short answer: Programming is writing clear, ordered instructions that a computer understands and follows step by step to solve a problem or get a job done. The computer itself does not understand our language — or code as we write it. It understands only one language: machine language, made of zeros and ones. What we write gets translated into that language by a middleman program called a compiler or an interpreter, and only then does the processor actually run the instructions.

Uploaded Image

Programming is writing instructions a computer can follow — step by step, with nothing left to guess.

What exactly is programming?

Imagine writing a cooking recipe for someone who follows it literally and never guesses anything: «heat the oven, add this, wait this many minutes». Programming is the same idea, but for a computer: a set of precise, ordered instructions, each with one clear meaning, executed in order. A program is those instructions written in a file, and code is the text of the program in a particular programming language. The crucial difference between a recipe and a program is that the computer does not fill in the gaps on its own: if you forget a step or write a vague instruction, it will stop — or do something different from what you meant. That is exactly why precision is the most important skill in programming.

How does a computer understand code in the first place?

Inside a computer, everything is electricity: current flowing, or not flowing. That is why information is represented with just two digits: 0, meaning «no current», and 1, meaning «current» — this is the binary system. The processor (CPU) understands only instructions written in this form, called machine language: long strings of zeros and ones, each string meaning a single order such as «add these two numbers» or «store this value in memory». Writing a whole program directly in machine language is possible in theory but almost impossible in practice: one simple line turns into dozens of binary instructions, and a single wrong digit breaks everything. That is why nobody writes real programs in machine language today.

What are programming languages, and why do they exist?

Programming languages are a bridge between the human mind and machine language: words close to English and familiar mathematical symbols, like let, if, and total, instead of strings of zeros and ones. You write what you want in a language close to how you think, and another program handles the translation into machine language. That is why hundreds of languages exist: each one was designed to be comfortable for a particular kind of work — web pages have their languages, phone apps have theirs, data analysis has its own — but the core idea is the same in all of them: ordered instructions, translated into machine language, then executed.

What is the difference between a compiler and an interpreter?

A compiler translates the whole program once, before it runs, and produces a ready executable file that works directly afterwards without being translated again. An interpreter works differently: it reads the program line by line, translates each line and runs it immediately, then moves on to the next — it produces no standalone executable file, and it must be present every time you run the program. That is why a compiler's errors all appear before the program runs, while an interpreter's errors may appear during the run, at the line where the problem is. A famous example of an interpreted language is Python; a famous example of a compiled language is C++. In reality, many modern tools mix the two approaches (translating on the fly while running), but understanding the basic difference is more than enough for now.

Worked example: your first real program — a shop invoice

This is a complete program in JavaScript — the language of web pages, which we will learn in this series — and it calculates the total of an invoice from a price and a quantity. Copy it as it is and try it using the steps right after the code:

let price = 50;
let quantity = 3;
let total = price * quantity;
console.log("Total: " + total + " EGP");

What each line does: the first line declares a variable named price and puts the value 50 in it — a variable is just a name for a place in memory that holds a value. The second line declares another variable named quantity with the value 3. The third line multiplies the two values and stores the result in a third variable named total — 50 × 3 = 150. The fourth line prints a sentence on the screen, joining the text «Total: » with the result 150 and the word «EGP». The expected result when you run it is exactly one line:

Total: 150 EGP

Now try the power of variables yourself: change the second line to let quantity = 4; and run the program again. The result will change on its own to «Total: 200 EGP» without you touching the other lines — because the computer recalculates total from the new values on every run. That is the whole idea of a program: general instructions that work with any values, not with one fixed number.

How do you try this code yourself without installing anything?

Your browser already has a JavaScript interpreter built in. Open any page in Chrome, press F12 or Ctrl+Shift+J to open the Console, then paste the four lines and press Enter. The result «Total: 150 EGP» will appear immediately. And if you type a line with a misspelled variable name, a red error message will appear pointing at the line — do not be afraid of error messages; they are the first diagnostic tool you will learn, and in a later lesson in this series we will learn to read them line by line.

What mistakes do beginners usually make?

First: assuming the computer will «understand what I mean» — it executes what you wrote, literally, not what you intended. Second: memorizing code without understanding it — copy the code, change one number, and watch the result; that single experiment teaches more than ten pages of reading. Third: jumping between languages before mastering the basics — variables, conditions, loops, and functions are almost the same in every language, so whoever understands them in one language can carry them to any other with ease. Fourth: fear of mistakes — every programmer, no matter how experienced, sees error messages every day; the difference is that they learned to read them instead of running away from them.

The bottom line

Programming is writing precise, ordered instructions to solve a problem, and the computer does not understand those instructions directly — it understands only machine language, zeros and ones executed by the processor — so a compiler translates them all at once, or an interpreter translates them line by line. A variable is a name for a value in memory, and a good program is general instructions that work with any values, as you saw in the invoice example: change the quantity and the result changes on its own. In the next lesson in this series, we will build your first HTML page, line by line, with no tools at all: How to Build Your First HTML Page (in Arabic).

Try writing your first program on HotGPT for free

Ask it to explain any line you did not understand, or to change the invoice example so it calculates a discount — and compare the result yourself.

HotGPT's monthly subscription starts at $2 via PayPal — subscribe and get activated within minutes

كتب بواسطة وحيد الفار

هذه المدونة برعاية موقع https://hotgpt.pro

تعليقات