Search code examples
c++pythoncompilationinterpreterexecution

Why does there seem to be tension between the simplicity of a language and execution time?


It seems to me that languages that are quite simple to use (i.e. Python) often have slower execution times than languages that are deemed more complex to learn (i.e. C++ or Java). Why? I understand that part of the problem arises from the fact that Python is interpreted rather than compiled, but what prevents Python (or another high-level language) from being compiled efficiently? Is there any programming language that you feel does not have this trade off?


Solution

  • Lets compare C and Python. By most accounts C is more "complex" to program in than say, Python. This is because Python automates a lot of work which C doesn't. For example, garbage collection is automated in Python, but is the programmer's responsibility in C.

    The price of this automation is that these "high level features" need to be generic enough to "fit" the needs of every program. For example, the Python garbage collector has a predefined schedule/garbage collection algorithm, which may not be the optimal for every application. On the other hand, C gives the programmer complete flexibility to define the GC schedule and algorithm as she wants it to be.

    So there you have it, ease versus performance.