I have a 200K-line Python app that uses 5-10 C extensions plus a few Cython 
modules I wrote for content-defined file chunking and a dedup hash table. 
Performance in general is good, but Python has its limits in several ways:

  * threading allows sharing data but the GIL limits performance
  * multiprocessing allows message passing without the GIL, but there's 
overhead to code, exchange, and decode messages
  * large data structures become impossibly large because of 24/28 byte integers
  * operating on large data structures is slow because of Python's VM



I love Python, and as one of the most popular programming languages in the 
world, if not _the_ most popular, other people apparently love it too. But I 
have hit its limits.

If it was possible to get reasonably maintainable Nim code from Python source, 
even if it required extensive editing, I think that would be huge. It's not 
like we're talking about converting some niche language like OCaml, Scala, 
Haskell, Erlang, Elixir, etc. to Nim. That would be a waste of time. But when 
you're talking about converting the most popular programming language on the 
planet, I think that would justify a lot of effort.

While it is possible to use Nim like a Cython replacement to speed up certain 
slow parts of a Python program, and that may be the best way forward for an 
individual or small team, it has limitations similar to multiprocessing: you 
still may have to take a lot of Python data, convert it to native Nim 
structures, do something with them, then convert it all back to Python, and 
that won't be fast. I haven't tried it, so can't say whether it's worthwhile or 
not.

One way to see how reasonable it is to do a real Python to Nim transpiler would 
be to start manually converting small Python programs, like at 
[https://rosettacode.org/wiki/Category:Python](https://rosettacode.org/wiki/Category:Python).
 The advantage of starting with real programs vs a grammar is that you'd be 
putting effort into converting things that people use all the time rather than 
beating your head against a wall trying to figure out how to convert some 
esoteric Python OO construction that maybe only a few people actually use. If a 
transpiler converted 75% of the code and left the other 25% of "weird" stuff to 
be done by hand, that would be huge. Someone there wrote the weird Python, 
someone there can convert it by hand.

This would also be a great tool for Python programmers to learn Nim. If a 
person is already familiar with their Python program, seeing a decent Nim 
translation would be a great way for them to map the Python concepts they 
already understand, to Nim.

And it isn't just about performance. Have you ever tried to do a static build 
of a Python program that uses C extensions (not the ones that come with 
Python), Cython modules, and needs an updated OpenSSL, for 3 platforms? Try it. 
It ain't fun.

Or if you have a C library you'd like to use, like the new Blake3 hash 
function, that doesn't have a Python binding yet. Ever seen those C-to-Python 
modules, with refcounts all over the place? What if you forget a few and your 
program starts crashing regularly. How do you debug that? Again, not fun.

Those are some of my reasons for looking at Nim. I looked at Go, and while it's 
much more mature and stable because of Google, it doesn't do much for me. Rust 
is way too fussy (Nim is too sometimes) and Rust is starting to look like APL. 
Compared to C++, which is a mess I never even wanted to learn, Rust might be 
wonderful, but they're too much "kitchen, bathroom, and laundry sink" for me. 

Reply via email to