Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 671
Madison May Avatar asked Dec 12 '22 23:12

Madison May


2 Answers

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.

like image 71
Sachin Avatar answered Dec 14 '22 13:12

Sachin


The problem with efficiency in high-level languages (or, at least, the dynamic ones) stems from the fact that it's usually not known WHAT operations needs to be performed until the actual types of objects are resolved in runtime. As a consequence, these languages don't compile to straightforward machine code and have to do all the heavy lifting behind the covers.

like image 31
Karol Nowak Avatar answered Dec 14 '22 12:12

Karol Nowak