Back to series
· 7 min read

What Is a Programming Language?


1. What Is a Programming Language

A programming language is a formal language used to write computer programs. Developers use programming languages to describe computational tasks, business logic, and execution rules; a compiler, interpreter, or runtime environment then processes the program so that the computer can complete the task according to the intended logic.

Put simply, programming languages address one core question:

How do we turn human computational needs into instructions that a computer can understand and execute?

For example, here is a simple calculation program written in Python:

a = 10
b = 20

result = a + b

print(result)

This code expresses the following operations:

  1. Define two variables.
  2. Add the two variables.
  3. Assign the result of the calculation to a variable.
  4. Output the result.

The program finally outputs:

30

Programmers do not need to write the binary instructions that the CPU executes directly; instead, they describe the computational logic in an easier-to-understand programming language.

This is the most important value of programming languages: through abstraction and formal expression, they reduce the complexity for humans to control computers.

2. What Problems Programming Languages Solve

A computer is essentially an electronic device that executes computational tasks according to instructions. It can perform mathematical operations, logical judgments, data storage, and information processing, but it cannot directly understand the natural language people use in daily life.

Programming languages mainly solve the following problems.

2.1 Describing Computational Tasks

Translating real-world problems into computational operations that a computer can execute.

For example:

  • Calculating product prices.
  • Counting orders.
  • Calculating a user's age.
  • Processing transaction amounts.
  • Analyzing business data.
price = 100
quantity = 3

total = price * quantity

print(total)

The program turns the unit price and quantity of a product into concrete computational operations.

2.2 Expressing Business Logic

Using language mechanisms such as conditional statements, loops, and functions to describe complex business rules.

For example, determining whether a user has administrator privileges:

if user_role == "admin":
    print("允许访问")
else:
    print("拒绝访问")

The program performs different operations depending on different conditions.

2.3 Managing and Processing Data

Using mechanisms such as variables, data types, arrays, collections, and objects to store, organize, and process data.

For example:

user = {
    "name": "张三",
    "age": 25,
    "role": "admin"
}

Programs can organize user information through data structures and then read and modify that data in subsequent business processing.

2.4 Controlling Computer Execution

Program instructions are used to control the computer and complete specified tasks, for example:

  • File reading and writing.
  • Network communication.
  • Database operations.
  • Graphical interface rendering.
  • Device control.
  • Multitasking.

Therefore, programming languages are not only used for mathematical calculations; they also form the foundation of modern software systems.

3. The Essence of Programming Languages: Abstraction and Formalization

To understand programming languages, one cannot stop at the level of syntax. What matters more is understanding the two core ideas behind them: abstraction and formalization.

3.1 Abstraction: Hiding Underlying Complexity

The lower layers of a computer involve a great many hardware details: CPU instructions, registers, memory addresses, data buses, and so on.

If programmers had to operate these low-level resources directly every time they wrote a program, software development would become extremely complex.

Programming languages encapsulate low-level complexity through abstractions at different levels.

For example:

a = 10
b = 20

print(a + b)

Programmers only need to focus on variables, the addition operation, and output; they do not need to operate CPU registers directly, nor do they need to manually write the corresponding machine instructions.

Common programming abstractions include:

Abstraction mechanism Problem it solves
Variables Provide readable names for data
Data types Abstract the representation of data and the rules for operating on it
Functions Encapsulate reusable computational logic
Modules Organize and isolate program code
Classes and objects Abstract entities and behaviors in the real world
Interfaces Define a unified behavioral contract
Generics Abstract common operations shared across different types

The higher the level of abstraction, the easier it usually is to express complex business logic—but it may also require more runtime support.

3.2 Formalization: Giving Programs Explicit Rules

Natural language is ambiguous.

For example:

If the order amount is fairly large, give the user a discount.

How large does the amount have to be to count as large? How big is the discount? Are there any other restrictions?

These questions are not clear in natural language.

Programming languages require developers to express things with explicit syntax and logic:

if order_amount >= 1000:
    discount = 0.9
else:
    discount = 1.0

The program's conditions, execution logic, and results all have clear definitions.

Formal expression mainly relies on:

  • Syntax rules (Syntax): specify how a program is written.
  • Semantic rules (Semantics): specify what meaning a program expresses.
  • Type rules (Type Rules): specify data types and their legal operations.
  • Execution rules (Execution Rules): specify how a program runs.

Together, these rules ensure that a program can be correctly processed by a compiler, interpreter, or runtime environment.

4. How Programming Languages Work

The CPU of a computer ultimately executes machine instructions, while programmers usually write in high-level programming languages.

Between the two, a certain conversion or execution process is required.

A typical program execution process is as follows:

flowchart TD
    A["Developer writes source code"] --> B["Compiler or interpreter"]
    B --> C["Code analysis and transformation"]
    C --> D["Generate machine instructions or execute intermediate representation"]
    D --> E["CPU execution"]
    E --> F["Produce runtime result"]

    style A fill:#E8F1FF,stroke:#3973C6,color:#1D3557
    style B fill:#EAF7EF,stroke:#3A9560,color:#245B3A
    style C fill:#EAF7EF,stroke:#3A9560,color:#245B3A
    style D fill:#FFF4DF,stroke:#C58A28,color:#765015
    style E fill:#F1EAFE,stroke:#8055B5,color:#49316D
    style F fill:#E8F1FF,stroke:#3973C6,color:#1D3557

Note that this is a simplified general model. The execution mechanisms of different programming languages vary, and they do not necessarily all generate standalone machine code files.

4.1 Source Code

Source code is code written by programmers using a programming language.

For example:

#include <stdio.h>

int main() {
    printf("Hello World");
    return 0;
}

This is a piece of C source code used to output a line of text to the screen.

Source code is the main form of expressing program logic, but it usually cannot be executed directly by the CPU.

4.2 Compilers and Interpreters

Compilers and interpreters are two important tools for processing program code.

Compiler:

Converts source code into object code, an intermediate representation, or another executable form for subsequent execution.

Interpreter:

Reads program code or an intermediate representation and executes the program according to the language rules.

For example:

Language Common execution mechanism
C Compiled into machine code for execution
C++ Compiled into machine code for execution
Java Compiled into bytecode, executed by the JVM
Python Usually compiled into bytecode, then executed by the interpreter
JavaScript Usually interpreted and executed by a JavaScript engine, combined with JIT compilation optimization
Go Usually compiled into machine code for execution
Rust Usually compiled into machine code for execution

Compiled and interpreted are not absolutely mutually exclusive language categories; modern language runtimes may use multiple execution technologies at the same time.

4.3 Machine Instructions and CPU

Machine instructions are instructions that the CPU can directly recognize and execute.

The CPU performs operations such as arithmetic calculations, logical judgments, and data reading and writing according to instructions.

For example:

  • Addition instruction: performs addition of two numeric values.
  • Jump instruction: changes the execution position of the program.
  • Load instruction: reads data from memory.
  • Store instruction: writes data to memory.

Different CPU architectures have different instruction sets, for example:

  • x86-64
  • ARM64
  • RISC-V

Through compilers, runtimes, and related toolchains, programming languages ultimately enable programs to execute on the corresponding computer platform.

5. Core Components of a Programming Language

A complete programming language is not just a set of code keywords; it is jointly constituted by multiple rules and mechanisms.

Core Component English Name Main Role Example
Syntax Syntax Defines how code is written if, for, function definitions
Semantics Semantics Defines what the code means addition, assignment, conditional judgment
Data Types Data Types Defines data types and rules of operation int, float, string
Variables & Constants Variables & Constants Store and represent data name, MAX_SIZE
Operators & Expressions Operators & Expressions Perform calculations and logical operations a + b, a > b
Control Structures Control Structures Control the order of program execution if, while, for
Functions & Methods Functions & Methods Organize and reuse program logic function, method
Modules & Packages Modules & Packages Organize and manage code module, package
Type System Type System Constrain data types and operations static typing, dynamic typing
Runtime Runtime Support program execution JVM, CLR, Python Runtime

Working together, these components enable a program to grow gradually from simple calculations into a complex software system.

VI. The Evolution of Programming Languages

The evolution of programming languages is essentially a process in which humanity has continuously improved computer programming efficiency, abstraction capability, and the ability to manage programs.

With the development of computer hardware, programming languages have gradually moved from directly manipulating hardware to high-level languages that are closer to human thinking and business expression.

6.1 Machine Language

Machine language is the binary instruction set that a computer can execute directly.

It consists of 0s and 1s, with different instructions corresponding to different CPU operations.

For example:

10110000 01100001

Machine language has the following characteristics:

  • It can be executed directly by the CPU.
  • It is closely tied to a specific CPU instruction set.
  • It is difficult to write and read.
  • Development efficiency is relatively low.

6.2 Assembly Language

Assembly language uses mnemonics to represent machine instructions, so that programmers do not have to write binary code directly.

For example:

MOV AX, 10
MOV BX, 20
ADD AX, BX

The code above represents the addition of two values.

Assembly language must be converted into machine instructions by an assembler.

Compared with machine language, assembly language is easier to read, but it is still closely tied to the underlying hardware architecture.

6.3 High-level Programming Languages

High-level programming languages reduce the complexity of program development through a higher level of abstraction.

Typical languages include:

  • C
  • C++
  • Java
  • Python
  • JavaScript
  • Go
  • Rust

High-level languages offer richer data types, control structures, functions, and module mechanisms, allowing developers to focus more on business logic instead of having to deal directly with large numbers of low-level machine instructions.

6.4 Development Directions of Modern Programming Languages

The development of modern programming languages is mainly concentrated in the following directions:

  1. Development efficiency: reduce development costs through concise syntax, automatic type inference, and rich standard libraries.
  2. Type safety: reduce runtime errors and improve code reliability through type systems.
  3. Concurrency capability: improve concurrent processing capability through threads, coroutines, actors, and other mechanisms.
  4. Memory safety: reduce memory errors through garbage collection, ownership, and borrowing mechanisms.
  5. Cross-platform capability: support different operating systems and hardware platforms.
  6. AI-assisted development: improve development efficiency through language toolchains, code analysis, and AI programming tools.