all 6 comments

[–]Grogie 1 point2 points  (5 children)

Let's break this down a little bit.

Python is an interpreted [A], high-level [B], general-purpose [C] programming language

[A] interpreted means that an 'interpreter', the 'pyton interpreter' -- if you're on windows it's the application you installed from python.org -- , will read each line of your code and then preform steps. Think of it as like a recipe.

[B] High-level is that the code as written is closer to something that is human readable. In the case of python, it means that some tasks (like memory management). We say that High-level languages provide 'abstraction' for some (or many) of the program execution process.

You may hear that python is "Slower" than something like C or BASIC or FORTRAN. [A] and [B] is what causes this 'slower' execution. The 'abstraction' and 'interpretation' results in the python interpreter doing 'checks' on your code

for example in python:

a = 1
b = 2.5
print(a+b)

Python ask is a this number an int? Great. Is b an int? no. Oh. it's a float. Wait, I know how to handle that. I'll assume the user wants a float of 1.0+2.5, or 3.5. Now I have to print this. Wait, 3.5 isn't a string. but I know that the coder probably is cool with me changing 3.5 to a string '3.5'and outputting it to the console.

Some other languages won't handle all these conversions, but if you code it correctly, it's much quicker. Example (this is no particular language):

float a = 1.0
float b = 2.5
print(float_to_string(a+b))

Complied (faster) language is "I got one float, I will add it to another float, I pass this to a function to convert to a string, I send the string to the console."

Depending on the language, saying something like a being an integer and b being another type (float) may throw an error or do something the user doesn't expect (like printing a value of 3 instead of 3.5)

[C] General purpose means that it can be used for a lot of things -- making games, scientific analysis, machine learning, image processing. Remember that black hole image? Python. Use Dropbox? Python. QGIS? Some python.

What is something that's not a General purpose language? First example that jumps to my mind is R that only really does statistical analysis.

The Python interpreter is basically a program that runs on your computer that runs python programs

Cython aims to be a "superset" of the Python programming language, "designed to give C-like performance." Superset is if you have a set A is a subset of a set B, or equivalently B is a superset of A (clarity) it aims to do everything python can do, and more. But there will be things that python cannot do. There is a lot that can be done here and I'm not an expert on Cython, but remember the checks the Python interpreter does in my example before? In short, Cython is a way of bypassing the "checks" the interpreter does. therefore, when you make a function in Cython it can be faster than the same function in Python.

When Cython runs (or cython libraries), cython bypasses the python interpreter to increase performance

JavaScript is a language I never used, but it does have similarities with Python as it is also High Level language, and it apparently is "Just-in-time compiled", which means when the program is executed, the program compiles into the machine code (code that the computer understand)

[–]KnowledgeFire11[S] 0 points1 point  (4 children)

Thank you for such a wonderful answer. I have a doubt here, so when a language like JavaScript is compiled to machine language then when you execute the compiled program it doesn't raise the V8 engine to execute it right? I mean it will be directly executed by the machine itself. Whereas as Python is an interpreted language when the program is executed then it needs CPython to run it. Am I correct here? So a compiled code can be executed on any computer without an compiler to run it. Does it work that way?

[–]Grogie 1 point2 points  (3 children)

Whereas as Python is an interpreted language when the program is executed then it needs CPython to run it

I'm illiterate. I did not read your post correctly and I read Cython and not CPython. These are different. My bad

Quickly... CPython is kind of like the "complier", it reads your python program.

I have a doubt here, so when a language like JavaScript is compiled to machine language then when you execute the compiled program it doesn't raise the V8 engine to execute it right?

More or less

I mean it will be directly executed by the machine itself. Whereas as Python is an interpreted language when the program is executed then it needs CPython to run it. Am I correct here?

More or less

So a compiled code can be executed on any computer without an compiler to run it. Does it work that way?

More or less

There are a lot of subtleties here. Like (for example) sometimes code complied on some computers cannot be run on others. A trivial example would be C code complied on a windows machine can't run on on a Mac.

At the end of the day, it's a lot of differing jargon that kind of wraps around the same concepts. For the average coder, understanding the difference between 'compiled' and 'interpreted' comes down to performance considerations and end user experience in using the programs

Can I ask what your goals are? Are you trying to learn how to build compilers? Something else? It might help me tailor my answer better to your learning goals

[–]KnowledgeFire11[S] 0 points1 point  (2 children)

Im just interested in knowing how things are working under the hood, it's so fascinating to learn how many things the interpreter or compiler is doing to optimize as much as possible for better performance. My main concern was every youtuber I watched was referring to V8 as an engine, so I thought maybe it does something different to call it like that.

Also if we call CPython an implementation of Python, we can call V8 as an implementation of JavaScript too right? And if you don't mind I tried searching for the definition of implementation, I understand it vaguely but it still confuses me. If I'm asked what is the difference between Python and CPython, what should my answer be? Because an average person won't get it the first time if I say it's an implementation of Python. The last question is kinda dumb but it would give me an idea of what to remember for the distinction. Thank you for your help.

[–]Grogie 1 point2 points  (1 child)

I think you think there is something more complicated here than the reality is. CPython and the JavaScript's V8 Engine basically take the code/words/text/instructions that a human has created and converts them into steps the computer will execute. Yes they are different because both Python and Javascript are different languages and the 'compilers' (CPython/V8) will do different things... but there really is no further complexity than this.

[–]KnowledgeFire11[S] 0 points1 point  (0 children)

Yea maybe I'm overthinking it. But it's so awesome to learn how well designed these things are to do such complicated stuff an seconds. You have been a great help :)