4 ms·
You have plenty of options to interface C and Python. You can use Cython to create Python bindings to C libraries or even better you can use cffi which works w
by ericfrederich 11y ago
You have plenty of options to interface C and Python. You can use Cython to create Python bindings to C libraries or even better you can use cffi which works with PyPy as well
- jboy 11y agoMy issue with Cython is that (at least as I've understood it from the tutorials I've read) it's a sub-language within Python, where you add Cython elements iteratively+incrementally (diverging from Python in the process) until the code runs "fast enough". I'd rather work directly in a full-featured, internally-self-consistent language (and Nim is a very nice language) from the start. Hence -- for me, at least: Nim. :)
- malmaud 11y agoHave you looked at Julia (http://julialang.org/ http://julialang.org/)?
- jboy 11y agoYes, I have, and Julia does look nice. It clearly has some very good libraries for scientific computing, and its syntax looks (to me) like an interesting combination of Python (which I like) and Matlab (which I don't like). Aside from an entirely-subjective preference that caused me to fall in love with Nim at first sight, there are practical reasons for choosing Nim over Julia. The overarching reason is that there is much more Python code in the world than Nim or Julia put together, and I think it will remain this way for a long time. (My startup previously worked almost completely in Python, for example, aside from some C or C++ extension modules and the usual Bash scripts for sysadmin.) Python also has some solid webserver frameworks, and is great for a variety of general-purpose tasks. So, I wanted a solution that would enable us to incrementally rewrite code as necessary, without needing to rewrite everything from Python all at once. Also, I have no desire to rewrite our webserver code from Python. Flask & Django are just fine. As I understand it (and please correct me if I'm wrong), Julia doesn't compile to C. So I can't compile snippets of Julia code and call them from my Python main-loop. In contrast, not only is this possible in Nim, but Nim's macro system & well-developed AST spec make it very easy to traverse my Nim procs during compilation, to auto-generate per-proc wrapper code in C.
- boyd 11y agoHey -- working on similar things here. Would love to follow up but don't see your email in your profile. Mind adding it or sending me a note? (mine is in my profile) Cheers!
- jboy 11y agoGreat! Email sent to the address in your profile.
- malmaud 11y agoYou're right that you can't compile Julia to static libraries (yet). Calling Julia from Python is not very mature at the moment, but calling Python from Julia is actually pretty robust via PyCall.jl (https://github.com/stevengj/PyCall.jl https://github.com/stevengj/PyCall.jl).
- deleted 11y ago[deleted]
- pathsjs 11y agoThe fact is that all these options are more complex than just using Nim. Cython is certainly great, but still Python objects and C structs differ, and you have to keep in mind the difference. Same for C functions and Python functions. And if you use the dynamic features of Python, you do not gain much in efficiency, because Cython does not have static dispatch, hence it has to rely on runtime checks. In a way, Cython is its own language, and it is not a particularly powerful one. The help you get from types is limited, as many things will just have type object. At this point, I just prefer to use Nim, which is friendly enough, and has overloading, generics, macros and many other features.