Search topics and sections

Computer programming is the work of designing, writing, testing, and maintaining the instructions that tell a computer what to do.[1][2] It means breaking a problem into smaller parts and arranging them into a sequence of instructions for a computer to carry out.[3]

Programmers write these instructions as text, called source code, in a programming language, and a finished set of instructions is a computer program. Other programs then translate the code into number codes that the processor (the part of the computer that carries out instructions) can run.[3]

What a program is

Programming is studied in computer science and is important to software engineering, where code is the final product of a software project.[2]

Programs and software

A computer program is an ordered list of computer instructions, each with only one possible meaning, for solving a problem with a computer.[4] Programs are called software. This sets them apart from hardware, the physical parts of the computer that run them.[4]

Algorithms

A program carries out one or more algorithms, which are step-by-step methods for solving a problem.[3]

A programming language provides the structures used to express algorithms. These include choices and loops (sets of instructions that repeat).[3]

Syntax

Source code must follow the exact rules of its language, called its syntax. A misspelled command or a missing bracket is enough to stop a program from running.[5]

How code reaches the processor

Levels of language

Languages range from a processor's own number codes to forms of writing close to mathematics or English. Low-level languages make the programmer manage the computer's details of data storage and operation. High-level languages hide those details and are easier to read and write, as the table below shows.[3]

Level What the programmer writes Trade-off
Machine language Number codes for the operations a specific computer can carry out directly Hard to read and write, and the codes differ from computer to computer
Assembly language Short names that stand for machine instructions Easy to translate, but needs detailed knowledge of the computer's design
High-level language Statements such as formulas, conditions, and loops Easier to read and write, but must be translated before it runs

Compilers and interpreters

A program in a high-level language must be translated into machine language before the computer can run it.[3] There are two main ways to do this.

  • A compiler translates the whole program into machine code, which is saved and run whenever it is needed.
  • An interpreter reads the program one instruction at a time and carries out the matching machine operations.

Some compilers add an in-between step.[3]

  • Some compilers first produce assembly language, which a program called an assembler turns into machine code.
  • Java compilers produce an in-between form called bytecode, which runs on the Java virtual machine.
Compiling and interpreting a program Source code total = a + b Compiler translates the whole program Machine code file (saved) 10110010 0110 illustrative Processor runs it Source code Interpreter reads one instruction at a time and carries it out Results Java: source code → compiler → bytecode → Java virtual machine Compiling Interpreting
A compiler translates the whole program into saved machine code, while an interpreter reads and carries out one instruction at a time. Java uses both steps: a compiler produces bytecode, which the Java virtual machine then runs.

The programming process

A program is built by first defining the task, then expressing it in a suitable language, and then translating it into code the machine can run.[4] The work usually moves through these steps.

  1. Define the task. Decide what the program must do.[4]
  2. Design a solution. Split the problem into smaller parts and pick a method for each.[3]
  3. Write the code in a chosen language.[1]
  4. Test the program to check that it gives the expected results.[1]
  5. Debug it by finding the mistakes behind wrong results and fixing the code.[1]
  6. Maintain it by updating and expanding the program after it is in use.[1]

These steps overlap in practice. Much design happens while code is being written, and programmers test their own work throughout.[2]

Programming involves several kinds of checking.

  • Verification checks whether the software meets the requirements set for it.[6]
  • Unit testing checks one small part of a program on its own.[2]
  • Integration testing checks whether the program's parts work together (see Testing).[2]

The IEEE Computer Society's guide to software engineering calls the hands-on work of programming software construction. It defines this as "the detailed creation of working software through a combination of coding, verification, unit testing, integration testing, and debugging."[2]

The programming cycleDefine the taskDesign a solutionWrite codeTestMaintainDebugpassesfailsfixnew needsIn practice the steps overlap
The usual steps of programming form a loop. Testing sends failures back through debugging, and maintenance brings new tasks.

Building blocks of a program

Variables and data

A variable is a named place in memory that holds a value. Programs store the results of calculations in variables as they go, a step called assignment.[7]

Programs also group values into data structures. Two common kinds are these.

  • An array holds a collection of values of the same kind. Arrays were central to FORTRAN, a programming language for scientific computing.[3]
  • A record groups different kinds of data, such as a name, an ID number, an age, and an address, into one unit. COBOL, a programming language for business computing, introduced records for business data, and they appear in nearly all modern languages.[3]

Control structures

Control structures decide the order in which instructions run. Britannica describes three basic ones.[7]

  • Sequence. Instructions run one after another. This is the default.
  • Selection. A conditional (if-then-else) chooses between paths depending on a test.
  • Iteration. A loop, such as a for loop or a while loop, repeats steps as often as needed.

These structures can be nested. A loop may hold another loop, and each branch of a conditional may hold its own sequences and loops.[7]

The short Python program below uses all three. The body of a loop or a branch (the instructions inside it) is indented, because indentation is how Python groups statements.[8]

# Sequence. These two lines run in turn.
prices = [4, 10, 7]
total = 0

# Iteration. Repeat for each price.
for p in prices:
    total = total + p

# Selection. Pick one of two paths.
if total > 20:
    print("Large order")
else:
    print("Small order")

The loop adds 4, 10, and 7 to get 21. Because 21 is more than 20, the program prints "Large order".

Three basic control structuresSequenceSelectionIterationStep 1Step 2Step 3Test true?Do ADo BRepeat?Do stepContinueyesnoyesno
The three basic control structures: sequence runs steps in order, selection chooses a path, and iteration repeats a step while a test holds. In the iteration chart the test comes before the step, as in a while loop.

Functions and libraries

A function (also called a subprogram, procedure, or subroutine) is a named block of code that takes inputs and produces a result.[7] Functions help programmers in these ways.[7]

  • Reuse. A function is written once and then used in many places.
  • Libraries. Commonly used functions come in a collection, called a library, supplied with a language.
  • Smaller problems. Functions let a programmer break a large problem into smaller ones.

Recursion

A function that solves a problem by calling itself on a smaller version of the same problem is called recursive.[7]

The factorial is a standard example. The factorial of a whole number nn of at least 1, written n!n!, is the product of the positive integers up to nn, so n!=1×2×⋯×nn! = 1 \times 2 \times \cdots \times n.[7] It can also be defined in terms of itself.

n!=n×(n−1)!for n≥2,1!=1n! = n \times (n-1)! \quad \text{for } n \ge 2, \qquad 1! = 1

Here nn is a whole number of at least 1. The Python version follows this definition line for line.

# n must be a whole number of at least 1
def factorial(n):
    # Stopping case
    if n == 1:
        return 1
    # The function calls itself on a smaller number
    return n * factorial(n - 1)

Recursion is often a simple way to write out an exact definition. It avoids the tracking of steps that a loop needs.[7]

Errors, testing, and debugging

Kinds of errors

Mistakes in programs are called bugs. Bugs are often sorted into three kinds.[5]

Kind What goes wrong Example Result
Syntax error The code breaks the language's rules Writing pint instead of print, or opening a bracket without closing it The program cannot run until it is fixed
Runtime error Something fails while the program runs Reading the sixth item of an array that holds only five The program is likely to crash
Logic error The method itself is wrong Writing < 5 where <= 5 was needed, so a loop meant to include the value 5 stops one step early The program runs but does not do what was expected

A good integrated development environment (IDE) usually points out syntax errors to the programmer.[5]

A logic error does not usually stop a program from running. The mistake shows up as behavior that is not what was expected.[5]

Where syntax, runtime, and logic errors appearWrite codeTranslate(compiler orinterpreter)RunOutputSyntax errorBreaks language rules.Program cannot run.pint instead of printRuntime errorFails while running.Likely to crash.reading item 6of a 5-item arrayLogic errorProgram runs, butthe result is wrong.using < 5 where<= 5 was needed
Syntax errors stop a program before it runs, runtime errors appear while it runs, and logic errors show up only as wrong results.

Testing

Testing runs a program on chosen inputs and checks the results. Two common levels of testing are these.[2]

  • Unit testing checks one small part of a program, such as a single function, on its own.
  • Integration testing checks that a program's parts work together.

Unit tests often run automatically. A test runner runs every test and flags any that fail.[2]

Some programmers write the tests before the code, a style called test-first programming or test-driven development. It can usually find bugs earlier, and it makes programmers think about requirements before coding.[2]

Testing cannot prove a program correct. As Edsger Dijkstra put it at a 1969 NATO conference, "Testing shows the presence, not the absence of bugs."[9]

Debugging

Debugging is the work of finding the cause of a bug and fixing the code.[1]

The word "bug" is older than computers, and its use in computing has a well-known story.[10]

  • Before computers. American engineers had called small flaws in machines "bugs" for over a century.[10]
    1. Engineers working on the Harvard Mark II found a moth stuck in one of its components. They taped it into their logbook as the "first actual case of bug being found."[10]
  • Afterward. Grace Hopper, who worked on the Mark II, and the rest of the team helped make the terms "bug" and "debug" widely used.[10]

Writing code that lasts

Good code is built so that people can understand it, check it, and change it later.[2] The software engineering guide lists several habits that help.

  • Keep it simple. Code should be "simple and readable rather than clever," because people can hold only so much detail in mind at once.[2]
  • Follow standards. Teams agree on coding standards for naming, layout, and indentation, part of a shared programming style.[2]
  • Reuse proven code. Programmers draw on libraries, modules (separate, reusable parts of a program), and open-source components (code published so others can read and reuse it) instead of rewriting them.[2]
  • Guard against bad input. Defensive programming protects each function from invalid inputs, often with assertions. An assertion is a check placed in the code that tests a condition while the program runs.[2]
  • Review the code. Code reviews, inspections, and static analysis find faults alongside testing.[2]

Programmers also track every change. Version control records changes to files over time, so a programmer can return to an earlier version, compare changes, and see who changed what.[11] Git is one such system.[11]

Programming paradigms

A programming paradigm is a general style of building programs. Languages are often grouped by the style they support, such as procedural, object-oriented, or declarative, as in the table below.[3][12][13]

Paradigm Main idea Example languages
Imperative (procedural) A program is a sequence of commands, organized with control structures and subprograms FORTRAN, C
Object-oriented Objects bundle data with the operations on it and hide internal details, and new objects can inherit abilities from more general ones Simula, Smalltalk, Java
Functional A program is built by applying functions to arguments (the inputs given to a function), in a mathematical style Lisp, ML, Haskell
Logic A program states logical relations, and the system searches them to answer questions Prolog

Functional and logic languages are both declarative. In such languages, a program states what is to be done rather than how to do it.[12]

Many languages mix styles. Python, for example, is object-oriented but can also be used for procedural or functional programs.[3]

The two Python examples below compute the same sum of squares, 1 + 4 + 9 = 14. The imperative version changes a running total inside a loop, while the functional version describes the result as one expression.

# Imperative style. Change a running total step by step.
total = 0
for x in [1, 2, 3]:
    total = total + x * x

# Functional style. Describe the result as one expression.
total = sum(x * x for x in [1, 2, 3])

Structured programming and goto

Early languages let programmers jump to any point in a program. FORTRAN, for example, had a GOTO statement that allowed code to run out of order.[3]

At the machine level, loops and conditionals are themselves built from such jumps.[7]

Free jumps made programs hard to follow, for three reasons.[14]

  • They scatter related parts of a program.
  • They make it hard to see which paths through the code are possible.
  • They can cause bugs that are hard to trace.

Two publications shaped the debate over jumps.

  • In May 1966, Böhm and Jacopini published a proof in Communications of the ACM.[15] It showed that any program with jumps can be turned into one that does the same thing using only loops and if-then-else choices, as long as extra true-or-false variables are added.[14] The result is known as the structured program theorem.
  • In March 1968, Dijkstra argued in a letter to the same journal, "Go To Statement Considered Harmful", that the goto statement should be removed from all higher-level languages.[16]

Structured programming builds programs from sequence, selection, and repetition instead of free jumps, the three structures Dijkstra proposed.[14]

Today the goto statement is rarely used in high-level languages.[7] Java reserves the word goto but does not use it.[17]

History

Before electronic computers

In 1843, Ada Lovelace published an English translation of Luigi Menabrea's article on Charles Babbage's Analytical Engine. Her own notes made up 41 of the paper's 66 pages.[18] Her final note, Note G, showed step by step how the engine would compute the Bernoulli numbers (a sequence of numbers used in mathematical formulas), though the engine was never built.[18]

Wires and switches

The ENIAC was finished in summer 1945.[19] It was programmed by six women chosen from the Army's human "computers," people hired to work out calculations by hand.[19][20] The six were these.[20]

They learned the machine from its diagrams and set up each problem across its cables, switches, and panels.[19] Designing the setup for each new problem, then connecting the wires and setting the switches, took many days.[21]

The Army revealed ENIAC to the public on February 15, 1946. It did not introduce the women who programmed it.[20]

Stored programs

Later computers kept their programs in memory, which let one machine perform many tasks.[4] The Manchester Baby, designed and built by F. C. Williams and Tom Kilburn, was the world's first stored-program electronic digital computer. It first ran a program successfully on 21 June 1948.[22]

Compilers and high-level languages

In the early 1950s, programs were still written by specialists in machine language.[23] In 1952, Grace Hopper completed the A-0 system, an early compiler that translated code written with mathematical symbols into machine language.[24]

High-level languages followed within a few years.

  • FORTRAN (1957) was designed by an IBM team led by John Backus for scientific computing.[3] IBM says a problem that once needed as many as a thousand hand-keyed instructions could be reduced to 47 in Fortran.[23]
  • ALGOL (1958 to 1960) was designed by a committee of American and European computer scientists. It introduced block structure, in which a program is built from blocks of data and instructions that each have the same structure as a whole program. It also brought Backus-Naur form, a notation for writing a language's syntax, the rules that say which code is valid in that language.[3]
  • COBOL (1959) brought an English-like notation and records to business computing.[3]

Structure and objects

After the high-level languages came new ways to organize programs.

Year Development Contribution
1966 Böhm and Jacopini proof Showed that jumps can be replaced by loops and choices[14][15]
1967 Simula Began object-oriented programming by adding information hiding to ALGOL[13]
1968 Dijkstra's goto letter Argued for removing goto from higher-level languages[16]
1980 Smalltalk Treated a program as objects sending messages to one another[13]
1990s on Java Became one of the most successful object-oriented languages[13]
Timeline of programming milestones, 1843 to 1980 1843 Lovelace'sNote G(AnalyticalEngine) 1945 ENIAC programmedwith cables andswitches 1948 Manchester Babyruns a storedprogram 1952 Hopper's A-0compiler 1957 FORTRAN 1959 COBOL 1966 Böhm andJacopini proof 1967 Simula, firstobject-orientedlanguage 1968 Dijkstra: gotoletter 1980 Smalltalk
Key events in programming, from Lovelace's 1843 notes to Smalltalk in 1980. The timeline is not to scale and has a break between 1843 and 1945.

Programming as a job

Duties

The U.S. Bureau of Labor Statistics counts computer programmers separately from software developers.[1]

  • What programmers do. They write, modify, and test code, turning designs made by developers and engineers into instructions a computer can follow.[1]
  • Overlap. In some businesses the duties of programmers and developers overlap.[1]

Jobs, pay, and education

The bureau reports these figures for the United States.[1]

  • Jobs. Computer programmers held about 110,800 jobs in 2025.
  • Pay. Their median annual wage, the wage at which half the workers earned more and half earned less, was $100,390 in May 2025.
  • Education. Programmers usually need a bachelor's degree in computer and information technology or a related field, such as mathematics.

Job outlook

The bureau projects that the number of programmer jobs will fall 7 percent from 2025 to 2035. It expects companies to have computers do more programming tasks, including through artificial intelligence (AI), and some tasks to shift to software developers.[1] AI is the ability of a computer to do tasks commonly linked with human thinking, such as reasoning.[25]

AI coding tools

Artificial intelligence in software development now includes tools built on large language models, such as GitHub Copilot, that suggest code as programmers work.[26] Studies of their effect on speed disagree.

  • In a 2022 controlled experiment, developers with Copilot built an HTTP server in JavaScript 55.8% faster than developers without it.[26] An HTTP server is a program that answers requests sent with HTTP, the rules that web browsers and servers use to exchange messages.[27]
  • In a 2025 randomized trial, 16 experienced open-source developers did 246 tasks in established projects they knew well. Each task was randomly assigned to allow or disallow AI tools. When AI tools were allowed, tasks took 19% longer, even though the developers afterward estimated that AI had cut their time by 20%.[28]

References

  1. Computer Programmers, Occupational Outlook Handbook, U.S. Bureau of Labor Statistics.
  2. Guide to the Software Engineering Body of Knowledge, Version 3.0, Chapter 3: Software Construction, IEEE Computer Society, 2014.
  3. Computer programming language, Encyclopaedia Britannica.
  4. Computer program, Encyclopaedia Britannica.
  5. Programming errors, BBC Bitesize.
  6. Guide to the Software Engineering Body of Knowledge, Version 3.0, Chapter 10: Software Quality, IEEE Computer Society, 2014.
  7. Computer programming language: Control structures, Encyclopaedia Britannica.
  8. An Informal Introduction to Python, Python Software Foundation.
  9. Software Engineering Techniques: Report on a conference sponsored by the NATO Science Committee, Rome, 1969, NATO Science Committee, 1970.
  10. Log Book With Computer Bug, Smithsonian Institution.
  11. About Version Control, Pro Git, git-scm.com.
  12. Computer programming language: Declarative languages, Encyclopaedia Britannica.
  13. Object-oriented programming, Encyclopaedia Britannica.
  14. Control structures, CS2111 course notes, University of Manchester.
  15. Flow diagrams, Turing machines and languages with only two formation rules, Communications of the ACM, 1966.
  16. Go To Statement Considered Harmful, Communications of the ACM, 1968.
  17. Java Language Keywords, Oracle.
  18. Ada Lovelace and the Analytical Engine, Bodleian Libraries, 2018.
  19. December 1945: The ENIAC Computer Runs Its First, Top-Secret Program, American Physical Society, 2022.
  20. ENIAC Programmers, Columbia University.
  21. ENIAC, Computer History Museum.
  22. History and heritage, University of Manchester Department of Computer Science.
  23. Fortran, IBM.
  24. Grace Hopper completes the A-0 compiler, Centre for Computing History.
  25. Artificial intelligence, Encyclopaedia Britannica.
  26. The Impact of AI on Developer Productivity: Evidence from GitHub Copilot, arXiv, 2023.
  27. Overview of HTTP, MDN Web Docs, Mozilla.
  28. Measuring the Impact of Early-2025 AI on Experienced Open-Source Developer Productivity, arXiv, 2025.

Figure

Subtopics

Adele GoldstineAdvent of CodeAlgorithms + Data Structures = ProgramsAnders HejlsbergAndrew Kelley (programmer)Armin RonacherArtificial intelligence in software developmentBarbara LiskovBetty HolbertonBidirectional transformationBjarne StroustrupBlack (software)Boilerplate codeBrian Fox (programmer)Class hierarchyClean CodeCode golfCodeforcesCODESYSCoding interviewCommon operator notationCompetitive programmingComponent PascalComputer programming in the punched card eraCongressional App ChallengeCore WarCWEBDavid Korn (computer scientist)David Wheeler (computer scientist)Defensive programmingDelimiterDifferentiable programmingDouglas CrockfordDouglas McIlroyEdsger W. DijkstraEffective JavaEven–odd ruleExtensible programmingFernando Pérez (software developer)FLOW-MATICFrançois FagesGary KildallGary RobinsonGeorge H. MealyGerald WeinbergGuido van RossumHacking: The Art of ExploitationHello, World! programHookingIdentity transformIn-system programmingInformInternational Collegiate Programming ContestInternational Obfuscated C Code ContestInternational Olympiad in InformaticsInterpreter (computing)Jackson structured programmingJamie ZawinskiJawed KarimJean BartikJed McCalebJeffrey SnoverJohn Chambers (statistician)Jon Bentley (computer scientist)Jonathan SachsKathleen AntonelliKazushige GotoKeno FischerKent DybvigLanguage constructLanguage primitiveLinus TorvaldsLiterate programmingLois HaibtMark OvermarsMethod chainingMichael HartlMiguel de IcazaMulti-Agent Programming ContestObfuscation (software)Ole-Johan DahlOOPSLAP. J. PlaugerP4 (programming language)Pair programmingParadigms of AI ProgrammingPaul Graham's essaysPidgin codePointer arithmeticPolyglot (computing)Program optimizationProgrammerProgramming idiomProgramming languageProgramming stylePseudocodePython ConferencePython Software FoundationQuantum programmingQuine (computing)Raymond HettingerReactiveXReentrancy (computing)Relational operatorRelocation (computing)Resource leakRich HickeyRichard StallmanRosetta CodeRuff (software)Runtime errorRust for LinuxRyan DahlScott GuthrieSelf-modifying codeSerializationSoftware developerSoftware ToolsSonic PiSource codeStale pointer bugState (computer science)Stephen R. BourneStructure and Interpretation of Computer ProgramsSystems programmingThe C Programming LanguageThe C++ Programming LanguageThe Practice of ProgrammingThe Unix Programming EnvironmentTheo de RaadtThreaded codeTim Peters (software engineer)Timeout (computing)Trevor BlackwellUltimate++Unreachable memoryValeria de PaivaVideo game programmingVirtualenvWalter BrightWard CunninghamWayne RatliffWeb (programming system)William A. SteinWinifred AspreyX10 (programming language)Zero-based numbering