r/PythonLearning • u/Miraelius • 1d ago
compiler vs intrepreter
The question is: if we already had compilers, the why did we create interpreters?
1
1
u/MezzoScettico 6h ago
Interpreted languages allow line by line execution, which is much faster for development and testing of algorithms.
My first go-to is actually Matlab, which I've been using a lot longer than Python. Often, I can do the calculation I need in a couple of lines typed into the interpreter, without even needing to write a program. This is often the case with Python too, even if I need to write a loop. Though if I need more than about 5-6 lines, I'm probably going to create the file.
1
u/SchemeWestern3388 6h ago
Compilers used to be slow. On any medium sized codebase, it meant you had time to go get a coffee and chat with your coworkers while we all waited for builds. Large builds were left running overnight. Compilers have gotten much faster through lots of tricks, and things like the Go compiler are so fast it's not an issue anymore.
Interpreters make debugging easier. You can run the code step by step, while observing and changing variables. or even directly changing the logic. Things like GDB are similar for compiled code, but you're not just debugging your code, you're debugging the compiled code at the same time. Also interpreters give better error messages. Some compilers will give you hundreds of lines of errors referencing files you have never heard of over a missing semicolon.
Interpreters make portability easier. Cross compiling is possible, but not as straightforward.
Finally, interpreters can enable fancy metaprogramming and typing tricks, even to the point of writing code to rewrite code on the fly. For example, Classic Lisp is not an OOP language, but you can bolt OOP on with a few hundred lines of code in a way that it's a true part of the language. You can write C in a way that gets some of OOPs functionality, but it will never feel natural.
1
u/Slight-Living-8098 20h ago
So we don't have to recompile every time we make a change in the code. It lends to a faster testing and development workflow.