"AI code generators are like compilers for translating natural language into a programming language" – I have heard and read this unfitting analogy quite a few times already.
It is misleading, as it sweeps a crucial technical point under the carpet and downplays some of the more serious consequences for people who have to deal with AI-generated code.
Compilers are deterministic, usually generating functionally equivalent code for a given input program on every run, according to language specifications.
Programmers usually do not have to check the machine code or the assembly code a native compiler generates, as its behavior is well-specified and, with mature compilers, also well-tested.
Programmers can expect the compiler to "just work", transforming code that is comparatively easy to read and write for humans into a form that is simpler for the machine to process, but difficult to read for humans.
Also, assuming the input code is written in a standardized language and uses its features in a well-defined way, switching compilers is relatively easy.
Yes, AI code generators also transform something that is easier to read – in this case natural language – into something that is simpler for the machine to process – in this case program code.
However, this is where the similarity ends.
The path from given prompt input to output code is practically inscrutable, warranting a lot more skepticism about the result.
In the general case, can you expect to get functionally equivalent code with the same prompts every time? No!
Can you even expect correct output? No!