Pyrex is a language specially designed for writing Python extension modules. According to the Pyrex Web site, “It’s designed to bridge the gap between the nice, high-level, easy-to-use world of Python and the messy, low-level world of C.” Almost any piece of Python code is also valid Pyrex code, but you can add optional static type declarations to Pyrex code, making the declared objects run at C speed.
What I hated the most about Python (or indeed ALL scripting languages) was always the lack of static typing….
Personally I prefer to use a SWIG wrapper around the C programs, rather than have to code in some horrid C-Python mishmash, it’s almost as abominable as Jython!
“What I hated the most about Python (or indeed ALL scripting languages) was always the lack of static typing….”
If I got 10 monkeys and let them bang on 10 computers keyboards for 3 hours and then gave you the code they that they created, I’m sure static typing would guide you somehow to fix what they created, line by line.
Now, if you created the code during three ours, with a nice design, separating the code among files/modules/classes/objects and maybe tests, and gave it to another person to extend it or fix a bug, it wouldn’t take much thought beyond a debugging experience to do it.
But, if you had used tools to generate the code for you (like a big IDE,) and then gave the code to this other person, but he didn’t have an IDE, I’m sure it would take a lot longer to figure out everything. Explanation? IDEs and code generators produce kind of hard to understand code. They produce more code than needed in other languages. It’s so abstract, that static typing is forced so a small change won’t become a bug (some times they do, even with static typing.)
Moral of the story: if you know what you are doing, you don’t need everything that someone that doesn’t know needs.
Python people (who love Python) may once in a while want/need to code something in C. To interface to a C library, for example, or speedup of a particularly computationally heavy piece of code. Pyrex makes C integration whole lot easier by requiring the coder (most productive and comfortable in Python) to only have to use as much C as necessary, while writing primarily in Python. It is an excellent tool, and is being very well received IMO.
“If I got 10 monkeys and let them bang on 10 computers keyboards for 3 hours”
You wouldn’t have code you would have broken keyboards and hungry monkeys.
“Now, if you created the code during three ours, with a nice design, separating the code…”
I totally agree…. who wouldn’t but how hard is it to have good comments? A good coder just knows to seperate such things as modules and classes etc.
“But, if you had used tools to generate the code for you (like a big IDE,) and then gave the code to this other person…”
Sounds to me like you are speaking of the GUI builders. I don’t know about you but no IDE that I’ve used just generates python code automagically, only GUI builders. I write every line of the program code. Also it would all depend on the experience of said user that you give this code to. You give me a python file using a GTK+ toolkit and I can approach it from several ways… you give me a file that is for WXwidgets but it’s an XRC file.. no problem… a little google searching, if needed, and off I go. WxGlade generates python code pretty cleanly.
> What I hated the most about Python (or indeed ALL scripting languages) was always the lack of static typing….
Well…I think you kinda missed the whole point of python…
You see, a complaint about the indentation scoping, while is something that is big in python, in reality is just in the language parser. The dynamic typing is something that is in the code of the language.
If you don’t like dynamic typing then you were either not using it enough, trying to fit old habits into a new paradigm, you were using it incorrectly.
I strongly suggest you read this:
http://dirtsimple.org/2004/12/python-is-not-java.html
Even though it talks about java, it applies to many other static languages as well. The point is to show that things are different in python and that you can’t program C++ in python. (the same way you can’t drive a truck and a mitsubishi eclipse in the same way)
Now back on topic!
Pyrex is an amazing tool! it let me easily use a couple of functions I needed from a c library without having to wrap it!! Although it might not be as useful for large library wrappings (I don’t know, never tried), it is great for the small quick c-like hacking needed.
Note that for purly spped improvements you might want to try out psyco. There are times when it preforms better.
A (not as useful) article about it:
http://www-106.ibm.com/developerworks/library/l-psyco.html
I am curious if there is anybody that has attempted to write an opengl program in psyco or pyrex with success. The problem in python is that the main loop is usually too intensive and is too slow in python. Usually it is implemented in C and everything else in python.
Pyrex is a great utility. I use it since about 1 1/2 years now for a project, and made excellent experience with it. Not so much concerning speed-up, which wasn’t the actual reason I started using Pyrex – though it does provide some speed-up, but that alone isn’t worth the hassle (this certainly might be different for other projects). But because it makes interfacing with existing C code so much easier than writing all the glue code myself.
I also use an embedded Python interpreter, and all calls between C (main) and Python go over Pyrex. It’s simple, easy and maintainable. Much more than when using Python extension API, which works as well but is significantly more complex to use.
<it>I am curious if there is anybody that has attempted to write an opengl program in psyco or pyrex with success.</it>
You may want to check Soya3d
http://home.gna.org/oomadness/en/soya/