Program libraries
| English | Chinese | Pinyin |
|---|---|---|
| program library | 程序库 | chéng xù kù |
| subroutines | 子程序 | zi chéng xù |
| static library | 静态库 | jìng tài kù |
| executable | 可执行文件 | kě zhí xíng wén jiàn |
| dynamic library | 动态库 | dòng tài kù |
Don't reinvent the wheel
- Most programs reuse pre-written code instead of writing everything from scratch.
- That code comes packaged in program libraries.
- They can be linked into your program in two different ways.
Computing concept lab
Classify concrete examples by the computing idea they demonstrate.
A collection of ready-made, reusable, tested code is a program ______.
Libraries save time and reduce bugs.
What a library is
- A program library 程序库 is pre-written code (subroutines 子程序, classes, modules) that programs reuse — e.g. a maths, graphics or network library.
- Benefits: saves time (off-the-shelf code), reliable (well-tested and widely used), and standardised (consistent behaviour).

A new program reusing ready-made routines from libraries

An IDE bundles the editor, a Run button and a debugger
A program library is:
Libraries provide ready-made, tested code (maths, graphics, network…) that a program can call instead of writing its own.
A benefit of using a library is that the code is:
Library code is tested, widely used and standardised — reusing it saves time and improves reliability.
Static vs dynamic libraries
- A static library 静态库 is copied into the executable 可执行文件 at compile time: the program stands alone, but the file is larger and must be rebuilt to update the library.
- A dynamic library 动态库 (DLL,
.so) is loaded at run time: executables are smaller, the library is shared by many programs, and updating it once fixes them all.

A static library is copied into the executable at compile time; a dynamic library is loaded and shared at run time
A static library differs from a dynamic library because it is:
A static library is built into the executable; a dynamic library is loaded at run time and shared between programs.
A dynamic library can be shared by many programs and updated once for all of them.
Because it is loaded at run time, one shared dynamic library serves many programs; updating it fixes them all without rebuilding each.
Match each trait to a static or a dynamic library.
Static linking copies code into the executable (bigger, self-contained); dynamic linking loads a shared library at run time (smaller, updatable once for all).
Why use a library
- A library is ready-made, tested code you can reuse instead of writing your own.
- It saves time, reduces bugs, and lets you build on the work of experts.

Utility programs: antivirus, backup, compression and defragmenter
You've got it
- a library = reusable pre-written code; benefits = time, reliability, standardisation
- static library: copied into the executable (stand-alone, larger, rebuild to update)
- dynamic library: loaded at run time (smaller, shared, updated once for all)