Programming Fundamentals

What is Programming?

Writing precise instructions a machine can execute, and choosing the data those instructions work on.

Level: beginner

What is it?

Programming is describing a computation in a language precise enough for a machine to carry out. A program is data (values held in memory) plus instructions (steps that read, compare, and change that data). A compiler or interpreter turns your text into machine instructions, and the CPU executes them one after another.

Why does it matter?

Every field in this curriculum — operating systems, databases, networks — is a program someone wrote. The habit that transfers is not syntax but decomposition: state the problem exactly, break it into steps a machine can do, and check each step against a small example.

Mental model

A recipe for a cook who follows instructions literally and never guesses. Skip 'preheat the oven' and nothing warns you; the cake is simply wrong. Programming is writing the recipe so a literal-minded cook cannot go wrong.

How it works

  • A program has three ingredients: values (data), operations on them, and control flow that decides which operation runs next.
  • Source code is only text. It becomes behavior after a compiler or interpreter translates it and the CPU executes it.
  • The machine does exactly what the code says, not what you meant. Most bugs are the distance between the two.
  • Every program is a pipeline: input, processing, output. Pure computation sits in the middle; I/O touches the outside world at the edges.
  • Abstraction keeps programs understandable: name a step, hide its inside, reuse it.

Steps

  • Understand the problem
  • Work one example by hand
  • Write the steps in plain words
  • Translate them into code
  • Run it and compare with the example
  • Fix the gap, then try an edge case

Code example: Data, steps, and a result

def average(numbers):
    total = 0
    for n in numbers:
        total = total + n
    return total / len(numbers)

print(average([4, 8, 6]))   # 6.0

Real-world usage

  • Automating repetitive work with scripts
  • Building applications, services, and developer tools
  • Every system in the OS, networks, and databases sections is itself a program

Common mistakes

  • Typing before you can solve one example by hand.
  • Copying code you cannot trace line by line.
  • Treating an error message as noise instead of the most precise clue you have. (Here, average([]) fails with a division by zero — the empty case was never considered.)

Interview questions

What is the difference between a program and a process?

A program is a file of instructions on disk. A process is a running instance: the program plus its memory, registers, and open files, managed by the OS.

What does a compiler do that an interpreter does not?

A compiler translates the whole program ahead of time into machine code or bytecode that runs later. An interpreter reads and executes source or bytecode at run time. Real implementations often blend the two.

How do you approach a problem you have never seen?

Restate it, work a small example by hand, look for a known structure, write the simplest correct version, test the edge cases, and only then improve its cost.

Related concepts

Continue learning

Browse the full computer science library