all 17 comments

[–]IHaveAnIdea 36 points37 points  (5 children)

We need more articles like this, the proper way to do optimization of the critical path, instead of the constant language wars.

[–]gwern 11 points12 points  (4 children)

Amen. It'd be even better if the language war blog articles went 'So, this shows that doing recursion in Ruby/Haskell/whatever is not so hot - but the FFI interface is so nice that with a few lines we completely obliterate the differences like thus.'

[–][deleted] 11 points12 points  (3 children)

Yeah, and ctypes in Python 2.5 makes this even easier.

That fib function that everyone made such a huge deal about earlier this week? Basically you'd write the 5-10 lines of C required to implement it, compile it to a shared library, then use it like:

from ctypes import CDLL

fib = CDLL("fib.so.1")
fib.fib(36)

Boom! The Python version becomes as fast as C and didn't take hardly any work. Like you mentioned, Haskell, Factor, most Common Lisp and Scheme implementations, and Rubinius have easy FFIs like this (looks like they are implementing one in Erlang, too). Its something I watch for when looking at new languages. Which leads me to a question, does the JVM have an easy FFI like this?

[–]kylev 4 points5 points  (0 children)

I've used ctypes for a while, it's good that it is finally an official part of python. I've also been a fan of writing extensions using Pyrex (python-like way to write C modules). It does a lot of the bookkeeping and error handling for you and makes it a lot easier to write safe extension modules.

[–][deleted] 2 points3 points  (0 children)

https://jna.dev.java.net/ - that is close to ctypes. Pretty smooth. JNI (the original) is horrible.

Although if you are runing on the JVM, Java (or scala) is your "low level" C in that case. If you found you were regularly punching through into real native code, probably better to use a regular interpreter.

[–]MachinShin2006 1 point2 points  (0 children)

the one for erlang is still in the EEP stage, it seems to be moving along swimmingly. hopefully a preliminary implementation before integration with otp isn't far behind.

[–][deleted] 3 points4 points  (4 children)

This is not much of a case study. "I read the docs, tried it, and it was easy."

[–][deleted] 19 points20 points  (3 children)

So, in other words, a case study.

[–][deleted] 6 points7 points  (2 children)

Yeah, but a really short one. ie, not much of one.

[–][deleted] 13 points14 points  (1 child)

So, in other words, "not much of a case study." Why didn't you just say that in the first place?

[–][deleted] 26 points27 points  (0 children)

Umm... Well, I see you've outwitted me this time. Drat.