Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is Cython/Jython an independent language?

So I spent a lot of time trying to fugure out what Cython and Jython are and I'm still (more) confused as anyone who just started computer programming. I heard that Cython is an extension, but..is also and indepent language??

What I think I've understood is that:

  1. Cython/Jython is just Python and you can use C or C++/Java libraries respectively with just a little bit of Cython/Jython syntax.

  2. It's meant to speed up performance as well as improve code readability when a task would be more efficient to write in C or C++/Java and, this is done by using statically typed variables.

Or is Cython/Jython just some sort of extension that is used sometimes but not independently? What I mean is, you'd still write everything in Python and then, for the tasks you'd rather use C or C++/Java for, you'd use Cython/Jython instead? (I know I still need Python installed and similar things as it's dependent.)

Because if it really is better, other than the barrier that it's still being developed since it's rather new, wouldn't the need for C or C++/Java completely go away as these are as easy as Python but as powerful as C or C++/Java?

like image 599
Neel Kamath Avatar asked Oct 23 '25 00:10

Neel Kamath


2 Answers

Jython FAQ:

Jython is an implementation of the Python language for the Java platform. Jython 2.7 implements the same language as CPython 2.7, and nearly all of the Core Python standard library modules. (CPython is the C implementation of the Python language.)

Writing Jython is similar to writing standard Python. The main difference is that since it compiles to Java Bytecode you can smoothly interact with Java Libraries. Of course it has a requirement on the JVM but has no Global Interpreter Lock (Famous GIL).

Cython:

Cython is an optimising static compiler for both the Python programming language and the extended Cython programming language (based on Pyrex)

So, Cython is first of all considered a compiler. It compiles your Python code to C which you then compile (with a standard C compiler) and run.

To further facilitate the integration with C/C++ it also has extended Syntax for specifying types, defining different kinds of functions and interfacing with C/C++ code. These, on one hand, allow Cython to generate more efficient code that by-passes the slow interpretation the Python VM usually does and, on the other, make writing extentions for Python a walk in the park since you don't need to familiarize with the Python C-API.


So, to answer your questions:

Cython/Jython is just Python and you can use C or C++/Java libraries respectively with just a little bit of Cython/Jython syntax.

Pretty much, yes. Jython is Python and uses Java Libraries with basic import statements. Cython is very similar to Python and, as you said, uses a bit of syntax to interface with C/C++.

It's meant to speed up performance as well as improve code readability when a task would be more efficient to write in C or C++/Java; and this is done by using statically typed variables.

For Cython this is the goal, for Jython it isn't. This is why Cython provides extended syntax to specify types while Jython does not.

Both languages are used independently (in the sense that you mean) but, Cython is usually deployed after profiling CPU-bound Python code and determining bottlenecks.

like image 72
Dimitris Fasarakis Hilliard Avatar answered Oct 25 '25 13:10

Dimitris Fasarakis Hilliard


Ok. Jython is an implementation of Python that converts python source code into java bytecode or object code as most people call it. So you basically write your programs using the python syntax, but the output of the source code when compiled to an object code is the java bytecode

Cython on the other hand is an implementation where by standard modules in the python language have been translated into the C language. So here, when you basically use a module, it is the python standard module, but for efficiency sake, under the hood, its C language or code that is executed

like image 33
user3566502 Avatar answered Oct 25 '25 15:10

user3566502