No history yet

Introduction to Programming

Giving the Computer Instructions

At its core, programming is simply the act of giving a computer a set of instructions to carry out a task. Think of it like writing a recipe. A recipe lists ingredients and provides step-by-step directions to bake a cake. A computer program does the same thing, but its instructions might be to calculate a budget, display a webpage, or run a game.

Computers are powerful, but they are also very literal. They don't understand nuance or context. They do exactly what they're told, in the exact order they're told to do it. The art of programming is breaking down a large, complex task into tiny, precise, and unambiguous steps that a computer can understand and execute.

A program is a sequence of instructions that specifies how to perform a computation.

Speaking the Computer's Language

So how do we give these instructions? We can't just speak to a computer in English. At their most basic level, computers only understand electrical signals that represent ones and zeros. This is called binary, or machine code.

Writing instructions in pure binary would be incredibly tedious and difficult for humans. That's why we invented programming languages. They act as a bridge, allowing us to write instructions in a format that's closer to human language. These languages use words, phrases, and symbols to represent complex binary instructions.

There are hundreds of programming languages, each with its own strengths and purposes. Some, like Python and JavaScript, are known for being relatively easy to learn. Others, like C++ or Rust, offer more control over the computer's hardware. Regardless of the language, they all serve the same fundamental purpose: to translate human ideas into machine instructions.

Hello, World!

While every program is different, most share a common basic structure. They often start with some setup, then execute a main sequence of commands, and finally produce an output. A long-standing tradition for programmers learning a new language is to write a "Hello, World!" program. It’s a very simple program whose only purpose is to display the text "Hello, World!" on the screen.

Lesson image

This simple exercise confirms that your setup is working correctly and shows you the most basic syntax needed to create a runnable program in that language. Here is what a generic version might look like:

function main() {
  print("Hello, World!");
}

This little program introduces the idea of a function (a named block of code) and a print command (an instruction to display output).

From Code to Action

Writing code is just the first step. For the computer to actually run it, the human-readable programming language must be translated into machine code. This translation is done by special programs called compilers and interpreters.

Translator TypeHow it Works
CompilerReads your entire program at once, translates it into an executable file.
InterpreterReads your program one line at a time, translating and running each line as it goes.

Think of a compiler as a translator who takes an entire book and gives you a fully translated version. An interpreter is like a live translator for a conversation, translating each sentence as it's spoken.

Languages like C++ and Java are typically compiled, which often results in faster-running programs. Languages like Python and JavaScript are interpreted, which can make them easier to test and debug on the fly. Both methods achieve the same goal: turning your code into actions the computer can perform.

Now that you understand the basics of what programming is, you're ready to explore the specific building blocks that make up a program.