From Latin 'codex' (book), earlier 'caudex' (tree trunk) — every line of code descends etymologically from a log.
A system of words, letters, or symbols used to represent others for secrecy or brevity; instructions written in a programming language; a systematic collection of laws or rules.
From Old French 'code' (system of laws), from Latin 'cōdex' (a book, a system of laws), earlier 'caudex' (trunk of a tree, wooden tablet for writing). Romans wrote on wax-covered wooden tablets made from tree trunks, and 'caudex/cōdex' transferred from the wood to the writing on it, then to a bound book, then to a systematic compilation of laws (the Codex Justinianus). The 'secret cipher' sense emerged in the 1800s; the computing sense in the 1940s. Key
The word 'code' literally means 'tree trunk.' Romans wrote on wooden tablets ('caudex'), and the word shifted from the wood to the writing to the book to the legal system to the cipher to the programming language. A 'blockhead' in Latin was literally a 'caudex' — a person as thick as a log — making 'code' and 'blockhead' unlikely etymological relatives.