I\'ve been programming for years (mainly Python), but I don\'t understand what happens behind the scenes when I compile or execute my code.
In the vein of a question I a
When I learned about programming, somewhere in the second half of the previous century, I learned that everything needs to be converted to machine code. Script languages would just decide which code to call based upon the scripted code. Compiled code would first be compiled to p-code, which stands for pre-compiled code, which needs to be linked to other precompiled code to create a full application. I liked Turbo Pascal back then, simply because Turbo Pascal compiled directly to machione code and it didn't use the intermediate p-code in-between. That is, until Turbo Pascal 4.0, which created *.tpu compiled units. Most other compilers would compile to the .obj format instead.
When Java was created, something relatively new started to become popular. Basically, a Java compiler just compiles code to some binary script file. This script could then be interpreted, although that mechanism soon changed too.
Nowadays, interpreters are nearly extinct. Most scripted languages will first be compiled to machine code, the machine code is then stored in some cache and thus it can be executed real fast, without the system having to re-interpret any repeating instructions. This works well for text and binary scripts. PHP would be an example of a text-based script. Java and .NET are binary scripts, since you generally compile the code to this binary script format. (They'll call it different, but I think binary scripts sounds better.)
In general, the trick is to convert the code to machine code, using whatever means possible. There have been many ways to do so and it's a bit complex to make it all clear.
I also remember the time when I could write a C++ application where SQL statements would be located inside the code itself. This was very practical too, but it required a preprocessor which would first parse the SQL statements from the code to convert this to other C++ statements and by replacing the SQL statements with those more complex C++ commands. Then the whole thing would be compiled to p-code. Then you'd need to link it with the additional SQL libraries and finally you had an executable.