3

When learning a compiled language like C or C++, you get to know the compiler. In order to run your code, you have to compile it first. Compiling your code translates it from a textual representation into something that can be executed. The resulting code is very fast and can make use of preprocessors and the like.

When learning a dynamic language like Python, Matlab, or Ruby, you get to know the interpreter. In order to run your code, you just type it into the interpreter. Thus, you can play with your code at runtime and change the behavior of your program on the fly. The downside of this seem to be that interpreted languages are rather slow and the lack of a clear compilation time seems to makes preprocessors impossible.

Then there are just-in-time compilers which are used like interpreted languages but with less of a performance deficit compared to compiled languages. But they generally do not sport preprocessors and do not output ready-to-run binaries.

And then I learned Lisp, which can be compiled, interpreted and what have you, all the while being both fast and having a powerful preprocessing system (macros). This seems to be common sense in the Lisp world, but not anywhere else.

Why are there no popular interpreters for C or compilers for Python? Why the strong divide between interpreted and compiled languages? (I know some projects exist that can compile Python or interpret C, but in general they seem to not be very popular).

bastibe
  • 16,551
  • 28
  • 95
  • 126
  • There are interpreters for C: http://root.cern.ch/drupal/content/cint. – Max Apr 03 '13 at 00:38
  • 1
    I would like to challenge some parts of your premise. Preprocessors are *entirely separate* and can run long before any compiler or interpreter (and they operate on source code, not on binaries). C and C-compatible languages have a particular preprocessor built in, but that has other reasons (desire for cheap compile-time abstractions). And, as you admit in the next sentence, there **are** Python compilers and C interpreters. They don't appear to be mainstream, but there are communities which use them. And in any case, "no interpreters/compilers" is obviously false. –  Apr 03 '13 at 09:54
  • @delnan True, "no interpreters/compilers" is wrong. I fixed that. Thank you for pointing that out. Regarding preprocessors: many compiled languages seem to have those built in (in particular, all C-derived ones), but few interpreted languages have one. Except for Lisp, which is both compiled and interpreted and has a preprocessor. And that is *useful*, so why don't other languages have all that? – bastibe Apr 03 '13 at 12:54
  • 1
    @bastibe Please give examples. The only (remotely popular) ones I know of are C, Obj-C (which is a proper superset of C), and C++ (which is almost a superset of C). However, there are many more "compiled" languages than that, for example Pascal + derivatives (in particular Delphi), Java, C#, ML + derivatives, Haskell, and Rust. You can take a preprocessor and run it over *any* source code, and in fact some people do this. Two examples: I've seen people suggest running m4 over Python code, and some Haskell projects run the C preprocessor over their code. –  Apr 03 '13 at 13:24
  • @delnan That is true, I have not looked at it like that. So in a way, the C preprocessor is kind of unique to C-derived languages. Most other languages do not have a built-in (or widely used) preprocessor. Interesting. Thank you for pointing that out. – bastibe Apr 04 '13 at 08:45
  • many would say that copmilers are machine-language interpreters. – Dru Aug 15 '13 at 23:40

1 Answers1

2

Most popular compiled languages were designed from the ground up to be compiled: they tend to avoid features that would make it difficult to produce efficient compiled code. These language features include the convenient "dynamic" ones such as dynamic typing, nonuniform containers, and ad hoc object namespaces.

So, an interpreter for a compiled language can't take advantage of the dynamic features that are available to a interpreted language, but lacks the performance advantages of a compiled implementation.

Conversely, a compiler must duplicate all features and behavior of an interpreted language, regardless of expense. In general, this means that the compiled program for an interpreted language will carry much of the overhead of the interpreter. As one example, any kind of eval() functionality effectively requires inclusion of the interpreter.

Finally, these effects are amplified by the mutually reinforcing advantages of large user base, good support, and robust implementation.

comingstorm
  • 25,557
  • 3
  • 43
  • 67