The Code Diarist

A diary about code

Libraries All The Way Down

May 3, 2025

Somehow, sooner or later, you just knew it, turtles were going to come into the story. We might as well trot them out now, let them take their bows, then get on with the rest of show.

Once upon a time when the world was flat, people imagined the Earth as a giant disk riding on the back of a great turtle. The apparent motion of bright things in the sky could be explained easily as resulting from the turtle walking slow circles beneath a canopy of motionless stars.

Objection: different things in the sky move at different speeds. How does one turtle, walking alone, achieve this effect? Oh, easily; it stands upon an even larger turtle.

And what does this second turtle stand upon?

The ancient philosopher could only sigh and say, It’s turtles all the way down.

My previous entry in this diary grumbled about depending upon code libraries previously written by others, to provide foundations for code that I write. I would do better to express gratitude.

Mostly I write code for microcontrollers, such as the Arduino widely familiar to hobbyists like me. Now be honest: nearly every line of code I write depends upon someone else's code made available to me in a library.

A program uses a library by including it in the list of instructions. For example, every program for an Arduino controller begins by including the Arduino.h library this way:

#include <Arduino.h>

Libraries contain pre-written instructions, such as the following list, found in the Arduino library, of definitions for important numbers used in math:

#define PI 3.1415926535897932384626433832795
#define HALF_PI 1.5707963267948966192313216916398
#define TWO_PI 6.283185307179586476925286766559
#define DEG_TO_RAD 0.017453292519943295769236907684886
#define RAD_TO_DEG 57.295779513082320876798154814105
#define EULER 2.718281828459045235360287471352
		

Do you remember PI from junior high? Our math books called it by its Greek alphabet letter, π. Given the definition in the Arduino.h library, a program can refer to the number PI by name. It is less effort to write that way compared to typing the actual number by hand, and helps to avoid math mistakes due to typographical errors. I am of course going to embrace such a library and turn it to my good.

Libraries stack upon each other like turtles sunning on a swamp log. The Arduino.h library includes other libraries, such as one that makes it easy to print of cheerful greetings to the user's computer screen by writing, simply,

Serial.println("Greetings, Thou Worthy User!");

Trust me, you do not want to delve here into the deep code that sends messages through the Serial communications hardware inside microcontrollers and computers. How nice it is to just include a library that makes the machinery run smoothly.

The Arduino-specific libraries, in turn, may depend on deeper-level C-language libraries. It’s libraries all the way down.

Regardless of how much pride I feel toward the code I write myself, I must appreciate my debt to all the writers who sat down before I came along and produced the many turtles that my world — and yours — ride upon today.