Hacker News new | ask | show | jobs
by tda 89 days ago
One thing with python is that usually I will use one of the many c based libraries to get reasonable speed and well thought out abstractions from the start. I architect around numpy, scipy, shapely, pandas/polars or whatever. So my code runs at reasonable speed from the start. But transpiling to rust then effectively means a complete redesign of the code, data structures, algorithms etc. And I have seen the AI tools really struggle to get it right, as my intent gets lost somewhere.

So what I do now (since Claude Code) is write really bare bones (and slow) pure python implementation (like I used to do for numba, pypy or cython ready code), with minimal dependencies. Then I use the REPL, notebooks and nice plotting tools to get a real understanding of the problem space and the intricacies of my algorithm/problem at hand. When done, I let Claude add tests and I ask it to transpile to equivalent Rust and boom! a flawless 1000x speed upgrade in a minutes.

The great thing is I don't need to do the mental gymnastics to vectorize code in a write only mode like I've had to do since my Matlab days. Instead I can write simple to read for loops that follow my intent much better, and result in much more legible code. So refreshing!

And with pyO3 i can still expose the Rust lib to python, and continue to use Python for glue and plotting

1 comments

Cython and all the libs you mention use the c-api, which is the #1 thing python needs to lose to be competitive.

I wish someone writes a stdlib without using it. My attempt from a few months ago in a repo under the py2many org.

> Cython and all the libs you mention use the c-api, which is the #1 thing python needs to lose to be competitive.

Quite hard to lose the #1 reason people use the language for.

The #1 reason people use it is because it allows you to focus on the problem you're solving rather than the syntax, memory management or some other aspect.

Most people don't even know what C-API is or why it slows things down.

Compatibility is made into a bigger deal than it is. That's the COBOL argument.

I wish the python community focused more on why openclaw and opencode are getting written in typescript, not python.

Why aren't agents more efficient at translating python code into shippable end user binaries using fast interpreted -> compiled agentic loops and attempt memory safety only for binaries/libraries with a large distribution.