A Conversation for Python - the Programming Language

Complementary to C/C++ and Java too

Post 1


The great thing about Python is the fact that its use is complementary to C/C++. It is near-ideal for integrating modules written in those languages [interfaced via SWIG - integration with C++ is a bit tricky to specify because of name mangling] with flexible Python code - great for rapid prototyping and gradual transition to C/C++ when performance becomes an issue. This can also be done with Perl, but Perl's somewhat arcane syntax is great for text manipulation but poor for clear understandable code.

Python has also been extended to work with Java in the form of Jython (http://www.jython.org). The integration of Jython with Java is even better than that of C/C++ because Java introspection obviates the necessity of a SWIG-like layer and Java classes and objects can be directly embedded in the Jython code. With jythonc, it is possible to create Java classes written entirely (with the exception of Java signatures) Jython code - jythonc creates a wrapped Jython interpreter. This is a superb tool for testing and experimenting with Java development. There are downsides: it is quite slow (as you might expect from an interpreted language lying on top of another essntially interpreted language) so I would think hard about its benefits before justifying shipping it in production code, and the weakly typed nature of Python means that you have to consider how Python types map to Java types particularly with regard to overloaded functions [oops sorry - I mean *methods*, of course smiley - winkeye]. Also the documentation is sparse compared to the generally excellent C-Python documentation and there are numerous gotchas : e.g. implementing a Java interface - as opposed to class - in Jython code (exactly how you would subclass in normal Python) does not create something that inherits the basic Java Object methods such as notify/wait - even though Jython objects are implemented in Java! I appreciate this is 'logical' in the sense that Jython objects even if they implement a Java interface are not Java Objects, but I was still a bit surprised to find this to be the case. And with jythonc wrapping, the Jython methods require a full Java signature to be specified - this is done in the __doc__ string: the jythonc compiler is - or at least used to be - particularly finnicky about the precise formatting of this string, e.g. no spaces after the opening parenthesis and the Java type name of the first parameter. And I did find a problem once upon a time with inconsistent use of tabs and spaces in the dowloaded jythonc.py code resulting in a parse failure; this is something IMHO that Guido got well and truly *wrong* - I don't think it's the place of a computer *language* to enforce stylistic convention no matter how good [what happens when you need to fling together code in a code generator?], particularly when it is prone to break because different whitespace characters have been used - this is something that people hate about the old Unix make utility, and it is annoying to see such a useful language perpetuate this problem. Begin-end block syntax, whether in the verbose Pascal form or the {} C form, has won out for very good reasons - and I have several former colleagues who dismissed Python as 'oh god thats the one with the bloody indentation rules' and refused to go any further with it. Okay more fule them but do you go to a job interview in a suit or in jeans? There, rant over. Finally Jython lags a little behind C-Python developments : C-Python is as I write (in the wee small hours of 2003/01/27) on v2.2 and Jython is on v2.1, which means there is no implementation of iterators as yet.

At ActiveState (http://www.activestate.com/Corporate/Initiatives/NET/Research.html?_x=1) there is also a .NET form of Python in development. This will allow the same interoperability with C# - and other CLR based languages?? - as Jython does with Java. So another cool tool awaits when you have to cram that .NET learning to get a job.

Key: Complain about this post

Complementary to C/C++ and Java too

Write an Entry

"The Hitchhiker's Guide to the Galaxy is a wholly remarkable book. It has been compiled and recompiled many times and under many different editorships. It contains contributions from countless numbers of travellers and researchers."

Write an entry
Read more