Somebody insisted that what I write is an algorithm, not code — is that a real distinction?
Talking to an engineer from a different background about a program I had written, I referred to it as code. He said he did not know what code meant, and that the correct word was algorithm.
I think I know roughly what each word means, but I could not defend the distinction on the spot, and it made me realise my definitions are fuzzier than I assumed.
Are these genuinely different things, and was he making a real point or a pedantic one?
@entropy_elif · 2w ago
They are genuinely different, and the relationship is straightforward once stated: code expresses an algorithm.
An algorithm is a procedure — a finite sequence of unambiguous steps that takes an input and produces an output. It is an abstract object. It exists independently of any language and can be written in English, in pseudocode, on a whiteboard, or in your head.
Code is a concrete text in a particular programming language that a machine can execute. The same algorithm has many possible codings; two implementations in different languages are the same algorithm and different code.
So binary search is an algorithm. Your twelve lines implementing it are code.
The distinction matters when you are reasoning about correctness or complexity, because those are properties of the algorithm rather than of the text. It matters much less when you are describing what you spent your afternoon on.
Reply
Report