Python becomes a platform

The recent announcement of clojure-py made some noise in the Clojure community, but not, as far as I can tell, in the Python community. For those who haven’t heard of it before, clojure-py is an implementation of the Clojure language in Python, compiling Clojure code to bytecode for Python’s virtual machine. It’s still incomplete, but already usable if you can live with the subset of Clojure that has been implemented.

I think that this is an important event for the Python community, because it means that Python is no longer just a language, but is becoming a platform. One of the stated motivations of the clojure-py developers is to tap into the rich set of libraries that the Python ecosystem provides, in particular for scientific applications. Python is thus following the path that Java already went in the past: the Java virtual machine, initially designed only to support the Java language, became the target of many different language implementations which all provide interoperation with Java itself.

It will of course be interesting to see if more languages will follow once people realize it can be done. The prospect of speed through PyPy’s JIT, another stated motivation for the clojure-py community, could also get more lanuage developers interested in Python as a platform.

Should Python programmers care about clojure-py? I’d say yes. Clojure is strong in two areas in which Python isn’t. One of them is metaprogramming, a feature absent from Python which Clojure had from the start through its Lisp heritage. The other feature is persistent immutable data structures, for which clojure-py provides an implementation in Python. Immutable data structures make for more robust code, in particular but not exclusively for concurrent applications.

 

Explore posts in the same categories: Programming

11 Comments on “Python becomes a platform”

  1. Pat Says:

    Clojure already has a native platform (the JVM), and it’s a pretty good one. There’s also been some work to bring it to JS as a platform, which would give us the ability to run it in web browsers.

    What is the benefit from being able to run Clojure on Python? Are there Python libraries that Clojure programmers are itching to use, that they can’t port easily, or find among the Java libraries? Are there systems that use Python for extension, which can now be extended with Clojure?

    I think Lisp is cool and compilers are cool and virtual machines are cool, so this is all very ‘cool’ but apart from the knowledge and documentation gained from isolating Clojure from the JVM, I don’t really see why this is important.

    I don’t see Python programmers migrating to Clojure now, because I don’t think the runtime was the limiting factor before. If Python programmers thought that Lisp-like metaprogramming was so important, they wouldn’t be Python programmers today! It’s not like they needed to sell it to their PHB but the JVM was a hard sell.

    • khinsen Says:

      The answer to most of your questions is “yes”. In my field of work, scientific computing, there is a very rich ecosystems of Python libraries and Python interfaces to C/C++/Fortran libraries that have no equivalent in the Java universe. There are also various applications that embed Python as a scripting language. In fact, for me, the JVM is the major obstacle to using Clojure.

      • Pat Says:

        Interesting, but I’m still skeptical. In a past life, I did scientific computing in Java. There is indeed a rich set of C and Fortran libraries (and a few really cool ones in Algol), but I never ran across any that were at all difficult to port to Java. That’s one advantage of Fortran being so simple. With a much higher-level language like Clojure, porting them should be that much easier. (Or you can call the native functions, if that’s your cup of tea, and the interface is a bit uglier but still usable.)

        I recognize that “scientific computing” is a very broad term, so I don’t know what you’re working on, but at least in my experience, porting a couple hundred lines of Fortran to Java ended up being a vanishingly small portion of my time.

      • khinsen Says:

        The most basic scientific libraries exist for Java, but not necessarily at the same level of sophistication as for C or Fortran. There’s nothing comparable to FFTW, for example, nor even anything close in performance to ATLAS, unless you use the JNI with all the trouble it brings.

        Where Python really shines is for higher-level domain-specific libraries. I do molecular simulation, which as far as I know is completely unsupported in the Java world.

  2. andrea crotti Says:

    I think clojoure is interesting for the immutability and the concurrency features, but I don’t see the point about the metaprogramming…

    Python has very good support for metaprogramming, and decorators for example are much easier to understand than lisp macros..

    • khinsen Says:

      In the terminology of functional programming, Python decorators are higher-order functions (that is, functions that take other functions as arguments and/or return a function). Metaprogramming is different because it works at the level of source code or abstract syntax trees (i.e. parsed source code). Metaprogramming means running code to modify other code before it is interpreted or compiled.

      There are many things you can do with metaprogramming that cannot be done using Python decorators. Examples are introducing new variables or defining new control structures. I agree however that decorators (being higher-order functions) are easier to understand and use than metaprogramming features.

  3. Chris Ing Says:

    There is some discussion on this post at:
    http://news.ycombinator.com/item?id=3708974

    • khinsen Says:

      In that discussion, several posters object to my claim that Python has no metaprogramming. There is no point in pursuing such a debate before first agreeing on a definition of metaprogramming. I use the term as it is commonly employed in the Lisp world: the possibility to implement syntactic abstractions.

      By that definition, Python has no metaprogramming features. I already commented on decorators above. In fact, decorators are just syntactic sugar for function wrappers that have been possible (but ugly) in Python since the very first release.

      The next candidate frequently cited is metaclasses. In spite of the common prefix meta-, metaclasses are not metaprogramming in the sense I defined, as they don’t work on a syntactic but on a semantic level. A metaclass changes how the syntactic elements in the input code are combined to make a class, but it can’t modify the source code.

      Finally, the ast module has been mentioned. This does indeed provide the possibility to modify syntactic elements, but not in standard Python programs. You have to create your own “Python dialect” in the form of a program that takes source code, parses it, and compiles it. The ast module and other parts of the standard library provide a lot of support, but standard Python code processing does not provide the required hooks into these mechanisms to provide metaprogramming as a Python feature.

      Finally, I suspect that metaprogramming is intentionally a non-feature in Python, and there are in fact good arguments for this. Metaprogramming is difficult to master and easy to abuse. It has been argued that metaprogramming in Lisp has prevented Lisp from becoming mainstream, because of the resulting fragmentation of the language. I don’t have an opinion on that, but I can understand language designers who decide not to provide metaprogramming.

      Which brings me back to my original post: with Python becoming a platform, it is finally possible to choose the most suitable language for each aspect of a complex piece of software, the platform ensuring interoperability.

  4. lynn Says:

    love this. many years of python, currently learning clojure but not loving the whole java ecosystem. this could be the best of both worlds.

    cool


  5. […] Python becomes a platform. Thoughts on the release of clojure-py. […]


  6. […] Python as a platform […]


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: