No history yet

Introduction to Programming

Giving the Computer Instructions

At its heart, computer programming is simply the act of giving a computer a set of instructions to perform a task. Think of it like writing a recipe. A recipe lists a series of steps you must follow in a specific order to bake a cake. If you miss a step or do it out of order, you won't get a cake. You'll get a mess.

Computers are very similar, but they're even more literal than the most particular chef. They don't have intuition or common sense. They follow instructions exactly as they are written. Programming is how we create those precise, step-by-step instructions that a computer can understand and execute.

The goal of programming is to take a complex problem—like calculating a budget or displaying a webpage—and break it down into tiny, logical steps that a computer can perform.

Speaking the Computer's Language

We can't write instructions for a computer in English or any other human language. Computers have their own language, which at the most basic level is just a series of ones and zeros called binary code. Writing instructions directly in binary would be incredibly tedious and difficult for humans.

This is where programming languages come in. They act as a bridge, allowing us to write instructions in a way that is more readable for us, which can then be translated into the binary code the computer understands.

Programming Language

noun

A formal language comprising a set of instructions that produce various kinds of output. Programming languages are used in computer programming to implement algorithms.

Just like human languages, programming languages have rules for grammar and structure. This is called syntax. Forgetting a semicolon or misspelling a command is like making a grammatical error; the computer won't understand what you mean.

From Human to Machine

So how does the code we write in a programming language get translated into ones and zeros? This translation is handled by special programs. There are two main approaches: compiling and interpreting.

A compiler reads your entire program at once, translates it into machine code, and saves this translated version as a separate, executable file. You then run that file to see the output. It's like translating a whole book into another language before anyone reads it.

A different approach is using an interpreter. An interpreter reads your program one line at a time, translates that line, and runs it immediately before moving to the next one. It's like having a live translator who translates each sentence as you speak.

FeatureCompilerInterpreter
TranslationTranslates the entire program at onceTranslates one statement at a time
ExecutionSlower initial preparation, but faster final executionNo preparation time, but slower overall execution
ErrorsReports all errors at the end of compilationStops execution as soon as it finds an error
Example LanguagesC, C++, RustPython, JavaScript, Ruby

The Structure of a Program

While every programming language has its own unique syntax, most programs share a basic structure. They are a sequence of statements that tell the computer what to do. The computer executes these statements in order, one after the other.

A common tradition for new programmers is to write a program that simply displays the text "Hello, World!" on the screen. It's a simple way to confirm that your setup is working correctly.

// This is a 'Hello, World!' program in C++

#include <iostream> // Includes a library for input/output

// The main function is where the program starts
int main() {
    // This line prints the text to the screen
    std::cout << "Hello, World!";
    return 0; // Indicates the program finished successfully
}

Don't worry about understanding every piece of that code just yet. The key takeaway is that a program is a structured text file with specific commands, written according to the rules of a programming language, to achieve a specific result.

Lesson image

Ready to check your understanding of these foundational concepts?

Quiz Questions 1/5

What is the core concept of computer programming?

Quiz Questions 2/5

The set of rules for grammar and structure in a programming language is known as its ________.

Now that you have a basic grasp of what programming is, you're ready to start exploring its fundamental building blocks.