logoalt Hacker News

If AI writes your code, why use Python?

557 pointsby indigodaddyyesterday at 8:45 PM596 commentsview on HN

Comments

pshirshovtoday at 10:57 AM

No reason, unless the project is simple. The more you can offload onto your compiler/typer - the shorter is the feedback loop, the better agents work.

Lack of strictly enforced static typing make agents fail much sooner with Python. In my opinion, Rust and Scala are the best targets for agentic flows - and, coincidentally, they have the most advanced typers among mainstream languages.

But any statically typed language behaves better than any dynamically/duck typed language. When I say "better" I mean delivery time and the amount of shipped defects.

Another thing which helps (but not generally applicable) - ask your agent to verify critical protocols with formal proof in TLA+/lean/coq. Agents are bad at formal proofs - but generally are much better than most of the humans.

bryanrasmussentoday at 7:29 AM

One obvious reason is Python's extreme readability, it has often been described as being as close to executable pseudo-code as one can get.

If you're using an LLM to write code I think the rules would be

1. Use a language you know really well so you can read it easily, and add to it as needed.

2. Use a language that has a large training set so the LLM can be most efficient.

3. Use a language that is easy to read.

If your language has a small training set or you don't intend to do much addition or you don't really know any language that well or are restricted from using choice 1 for some reason, 2 and 3 move up, and python has a large training set and it is easy to read.

show 10 replies
_boffin_today at 12:36 AM

Read the first few comments and surprised I didn’t see it, but training data. The voluminous amount of Python in the training data.

I could write in brainfuck with ai, but I presume, wouldn’t get the same results than if going with python.

My follow up question: with AI now, why care about a lang until you need to?

show 25 replies
bob1029today at 10:23 AM

Python might still be the best option if your goal is to perfectly one shot the solution and minimize token usage as much as possible.

However, if you are willing to stub your toes, retry, and pay more money, an entire new world opens up. Languages like python seem to fall apart faster in extremely large projects.

I've got a collection of interdependent .NET codebases with about 50 megs of raw source between them. Having C# be strongly typed seems like an essential backbone for keeping everything on rails in my agentic scenarios. The code edits have been flawless for several months now. I've got successful apply_patch usages that touch 20 files at a time. LLM code editing performance might be mostly language agnostic once we compensate for the strictness of the type system. More specifically, how much useful information is returned at compile time.

Compile time errors and warnings are probably the most powerful alignment mechanism available. Some ecosystems allow for you to specify your own classes of errors and warnings. I think tools like Roslyn Analyzers might be more powerful than unit tests in this application. Domain-specific compilation feedback feels like the holy grail to me.

https://learn.microsoft.com/en-us/visualstudio/code-quality/...

show 1 reply
fbrnccitoday at 2:25 AM

Why Python? Because I have written it for 10+ years, know how to debug it and I can smell it within 10 seconds of the agent writing code if it does something that is going to end in a huge foot gun. With any other language, not so much; I would need to relearn a lot. So I am going to be preferring python; where even with the speed that AI crams out code, I still feel somewhat in control. If I did this with Go or Rust, then it would feel more like "vibecoding" than AI assisted programming, just yolo the whole product.

show 3 replies
oxag3ntoday at 12:30 AM

If AI writes your articles, why use brain?

show 4 replies
niek_pasyesterday at 9:07 PM

Bit off topic but why in the world are people still posting on medium? The reading experience is abhorrent; I couldn’t even finish reading this article before a full screen popup literally blocked the sentence I was reading.

Is there some incentive I’m not seeing?

show 7 replies
elcritchtoday at 11:03 AM

For me it's all about Nim + LLMs. I'm greedy and want both fast-to-ship and fast-to-run? Readability comparable to Python but with strict static typing that LLMs can't "cheat".

I actually (mostly) enjoy reading the code that the LLMs create in Nim. It's quick to read and look for refactor or cleanups. Compile times in seconds so the LLMs is usually the slow piece. It's fun and productive. With Python + LLMs I'm seeing them just create ever more layers of unmanageable cruft.

Recently I wanted "magic" behavior to get OpenAPI types and swagger.json along with auto parsing my rest APIs for me. I had Codex make a library for me using compile time reflection and a sprinkling of macros. Done, simple.

p4bl0today at 6:57 AM

Not just for LLMs, but in general if code is produced automatically by a tool and isn't going to be a hundred percent proofread and tested by humans who could have written it manually, it's always better to use the safest possible language so that the compiler can catch most of the errors. So yeah, Rust or OCaml are good candidates. Performance is also a good point but it's a secondary issue in my opinion.

rchoweyesterday at 9:16 PM

Python has a much more mature ecosystem than Rust, especially for AI/ML stuff. I ran into a rust crate that purported to do a certain ML algorithm but did not do it correctly. I managed to write a replacement with Claude though.

I do think enforcing correctness at the type system level is a good idea for AI, which is why I often choose languages like C# and Rust over Python. However, for some things Python is definitely the correct tool for the job.

show 5 replies
kgeisttoday at 9:28 AM

Lots of comments here already, just my two cents. I work in R&D and I prefer prototyping things in Python with AI (although we're a 100% Go shop) because:

1) Python is expressive and has packages for everything => faster iteration times because much fewer tokens

2) It doesn't require a compilation step, so when I'm quickly iterating on something, especially if my laptop doesn't have the target hardware, the flow "copy the sources to the target machine and restart" is superfast (a couple of milliseconds)

3) Python most likely represents the largest share of training data, so almost all LLMs can one-shot almost everything

And when my prototype is ready, and we want to go to production, I can ask the LLM to port it to Go with all the necessary conventions/ceremonies and all.

fulafeltoday at 7:39 AM

> Go delivered most of the performance benefit at a fraction of the engineering cost. The biggest JS/TS shop on earth picked a harder, faster language for its flagship tool, and they did it because the effort calculus changed under them.

IME very few people think Go is harder than TS or JS - TS is quite complex and JS is a footgun range.

JS got popular for nontechnical reasons and TS is an attempt to make lemonade out of it.

RagnarDtoday at 11:23 AM

Really glad to see someone asking this question. After building a fairly significant AI tool using Python tools, I really wish AI/ML tools would all be rewritten to use an actually performant language - say, Rust - without transitive dependency hell on all the package versions.

fxjyesterday at 9:21 PM

You can of course use any language but here is my advice: you should use the language that you know best to make your life as uncomplicated as possible when you want to understand what the LLM was creating.

Remember, you are the judge whether the code is OK and if you use assembler you might get really performant code, but can you trust it?

Of course it might be a good incentive to learn rust or go. Or challenge yourself to learn something really cool like LISP, COBOL, FORTRAN, APL or J. (just kidding...)

just my 2 ct...

show 1 reply
vhantztoday at 12:59 AM

> A shipped app, in a language nobody on the team knew

Great! Let's look back on this not too far in the future.

show 3 replies
kekpektoday at 11:22 AM

I also try to use Ruby because it's much more readable than anything else. And yes, still need to review and understand what code AI generated there

GavinAndereggtoday at 2:23 AM

It's strange to me that this blog post was written in English. If AI is available, why aren't we all communicating in Lojban? [0] It's an obviously superior language. What does it matter that many people already communicate in English and much of computing depends on that language? AI doesn't care about that. Plus, if you ever need to edit Lojban without AI, you should be able to pick it up in a few weeks, right?

[0]: https://en.wikipedia.org/wiki/Lojban

show 12 replies
rundigen12today at 10:12 AM

And why use readable variable names? "aA=q_(c8z,fW8)"

Seriously though, almost all the examples in TFA are of rewriting existing code. It may be that Python is still best for the rapid dev iteration. Then sure, cross-compile into Rust via the LLM.

Plus, If we care about token usage counts, Python has a lot more opportunities for compact "import thing_I_need" than having to generate entire libraries in Rust.

__mharrison__yesterday at 9:21 PM

AI's are really good with Python. Quick turnaround. Easy to read. Tons of training data/examples. Many of the same reasons we wrote Python before.

Another benefit to using Python, is if you subscribe to writing/vibing a throwaway version first, a Python version is 100x better than a spec.

(Disclaimer: I teach Python and AI for a living and am doing a tutorial at pycon this week, Beyond vibe coding. Am also using other languages as there are times when Python isn't appropriate)

show 4 replies
dsiegel2275today at 11:15 AM

10-100x faster? Maybe for strictly IO bound applications - but if you are building a web app you won't see that performance as network latency dominates.

librasteveyesterday at 10:33 PM

Many here propose replacing Python with more performant, but less familiar languages - mostly Rust, Go. But I find the argument that the AI - HUMAN interface is the most important. A simple version of this is “no, stick with Python if that’s what you know”. A more interesting version is “use this new found AI leeway to move up the abstraction level”, “try something more expressive and human oriented”, “make a DSL and parser that suits the domain (and focuses the AI)”. Despite being a minority language, Raku is ideal for these aspects (esp with built in Grammars and general kitchen sink repartee) and works surprisingly well with most popular LLMs.

show 2 replies
alkonauttoday at 10:13 AM

Agreed. Even if Python or JS was the language I knew well, even if the platform ecosystem is the one I need, I'd _still_ make very sure to use at least strong types (even if not static) for anything an AI co-creates and is maintained longer term.

Rust isn't perfect due to rather long turnaround for compile/test iterations, but a lot of those can be avoided if the type checking is quicker than compilation. Rust is also more verbose than python and other very high level languages, which means your token budget is eaten more quickly as it works on a lower level.

bencedtoday at 7:41 AM

The lumping together of Typescript with Python is a mistake. Typescript is much faster (mostly due to engine investment), is much saner, has more expressive types, and generally has better ergonomics for the backend than Python.

dengtoday at 5:41 AM

> Nicholas Carlini, a researcher at Anthropic, orchestrated 16 parallel Claude agents to write a production C compiler in Rust.

No he didn't. The compiler is bascially useless as it produces vastly inferior code than gcc/clang.

beshrkayalitoday at 6:20 AM

For now it’s the exact same reason why you’d use Python when you’re writing by hand: so the code is more easily readable/editable by humans who are more likely to know Python than something like Zig. But I understand the point the post is trying to make, I don’t think we’re there yet.

show 1 reply
redbelltoday at 8:47 AM

> Andreas Kling, creator of the Ladybird browser and a career C++ engineer, ported Ladybird’s JavaScript engine from C++ to Rust in two weeks

Discussed here with 698 comments (https://news.ycombinator.com/item?id=47120899)

b800htoday at 7:10 AM

If you're working with an agent to write code, you want it in the most quickly-readable format possible. That's generally Python, although YMMV. I want to be able to skim and zoom in on parts of code that might need attention. This makes it easy.

If the code were written in Java, I'd have more to read. If it were in JavaScript, I'd be slower following the calls (although the type system might catch issues more quickly - not a problem in my experience). I think Python is a good choice.

show 1 reply
meander_watertoday at 6:52 AM

One underrated advantage of using Python or Typescript is that AI agents can inspect the code of installed dependencies.

This means you don't have to muck around with supplying the right documentation for each version of each dependency, or worry about hallucinated interfaces (at least with the latest models).

In the past you'd have to dig through a foreign codebase manually to figure out why a documented interface for a dependency is not working as expected, but frontier models automate that quite well.

show 1 reply
shibaprasadbtoday at 10:17 AM

Python is the 2nd/3rd best language for almost everything. So I guess it helps.

dragonelitetoday at 5:47 AM

Kind of my fear is that the industry and dev community will ignore new frameworks, languages, architectures etc because the LLM aren't trained on those new things.

For example low level converging to Rust, web frontends to something like React etc.

show 1 reply
skybrianyesterday at 9:31 PM

This seems sort of like asking whether a chatbot should answer you in English or Japanese. Obviously, it should use whichever language you understand. If you understand Python best, why not write code in Python?

But on the other hand, maybe you could learn some other programming language, particularly with AI help. If that's what you wanted to do anyway, it seems like a good time to learn.

kylecyesterday at 9:10 PM

This post resonates. I recently built a little web service to scratch an itch I've been having and after discussing the options with Claude we settled on Go, and honestly it's been fantastic. Highly performant, native threading, dead simple to deploy with containers. And I don't even know how to read or write Go.

show 1 reply
dizhntoday at 8:31 AM

In my experience Python is fine. However both Go and Flutter(Rust) are better due to the tools that are available, especially the compilers. Flutter in particular surprises me with how good LLMs are at it. Both might actually be thanks to good documentation. Maybe that they are not VERY fragmented and don't have a lot of baggage.

Frontend CSS/HTML is pretty bad though. Although they can work, it takes a lot of pushing. It's probably normal since they do not actually have eyes yet.

0xbadcafebeeyesterday at 9:25 PM

I know a couple languages fairly well: C, Perl, Python, Bash. I never formally learned Go, but as a test of AI coding, I started some vibe coded projects in Go. It worked very well: the code is minimal, there's few dependencies, and it compiles down to a static app. But most importantly, I can actually read the Go code and understand basically what it's doing. I can also use LLMs to critique the code if I'm uncertain. The big benefit of Go is the simpler language and "batteries included" standard library. This leads to fewer dependencies and less lines of code, which improves overall AI output. In theory, AI should be able to write better code faster in Go than in another language like Rust.

Python does have a much larger ecosystem of course, so with Go you have to develop from scratch what already exists in Python. But for smaller projects, you can also have an AI write a clean-room implementation in Go of some project in Python. So you aren't necessarily locked into one ecosystem anymore.

And in my experience, you don't even need to know the language. I have a co-worker who's basically not a programmer, but got multiple implementations of applications working sooner than our dev teams doing it by hand. You should be a coder so you can architect and orchestrate the coding, but 'language' isn't a barrier anymore.

show 1 reply
arjietoday at 3:52 AM

Actually, I do use compiled languages for this reason. Even Opus 4.7 and GPT-5.5 will leave unassigned variables lying around in Python code of sufficient size. If you've got sufficient testing you'll exercise all paths, and I imagine a good prompt would ensure adding testing with coverage to see that it does happen. However, I do not have (yet) such a system but using Go/Rust helps a lot because the compile phase actually helps detect correctness issues.

My other problem with most of the other ecosystems: ts/npm, python/uv, rust/cargo is that they all have build-time scripts that are controlled by others that execute automatically. This is a real problem because the LLM will just install things and proceed to send your home directory through a juicer. I feel a bit of a paranoiac now doing this, but I have a script that launches a podman container with just the source directory and a binary directory loaded (for caching) which compiles everything.

I know there's some sequence of steps I can take to protect myself, but if the LLM accidentally uses pnpm to run dev build scripts when I had the right config on npm or whatever, I know I'm screwed. So now I do all these shenanigans with Rust (to the extent that I vendor old deps sometimes). So the ideal language to me now is one with very few of these footguns and sandtraps which has a tight iteration loop.

show 1 reply
bozdemirtoday at 8:18 AM

Yea I take the step a bit further, why bother Rust ? Just go write assembly or better the executable bytes... You see ? Readability is very important :)

show 1 reply
caturopathtoday at 8:11 AM

Other correctly point out it does matter what language the code is in since the human does sometimes need to read and understand it.

But also, I suspect the article is just wrong. "The hard languages got easy first" isn't true in practice and the impressive examples given are not representative or as magical as the poster makes them out to be.

The takeaway might be right in the end, but the post isn't right in the beginning.

repirettoday at 5:17 AM

My experience is that there's a correlation between powerful type systems and the property that once your program compiles, it's correct. Compiles == correct is rarely true in C or JavaScript. It's often true in Haskell and Rust. TypeScript is somewhere in between C and Rust.

There's a niche available for a language which is relatively easy for a human to read, but with a very powerful at the expense of difficult to use type system. The language would let you make all sorts of assertions whose meaning are easy for the human to see, but to compile would need to come along with correctness proofs. The language is meant to be written by AI, which can battle the compiler, and write the proofs, but then read by humans who can verify that the AI wrote the program they wanted and/or direct the AI to make changes.

show 1 reply
rick1290yesterday at 9:56 PM

I'm still not sure. Would love thoguhts on this.. but in this new ai world we are in... is it better to go fullstack typescript? or go with proven mature frameworks? .net, ruby, django, etc? Seems TS is moving fast but maybe its time to not reach for the shiny object and stick with proven tech? or in 5 years will we regret it?

show 2 replies
stevefan1999today at 4:36 AM

Really controversial but my honest opinion: That's because programming languages, and its natural language counterpart, too, are nowadays increasing and more likely in becoming a political tool, rather than itself being a tech tool.

I observed this through observation of the attacks to Rust due to the huge presence of LGBT people.

Now while I'm pretty much straight myself, I don't reject LGBT people and don't want to partake in identity politics.

I just want things that works no matter what background you have, yet there are some people attacking Rust because of its inclusiveness nature.

And just like Linux is being perceived as nerdy and geeky and "gaming socks ready", the tokenization of things, and there attaching political meanings to it, are quickly coming to everything, so perhaps I'm too general here as well.

Let's say it is not political, but definitely adding more meanings to its technical origin and nature

show 2 replies
doublesockettoday at 6:24 AM

Why stop at getting AI to write Rust? If everything is vibe coded and code is no longer reviewed, get an LLM to devise its own ultra terse, super dense language intended solely for minimal token use and speed.

/s... sort of

show 2 replies
thefoundertoday at 4:40 AM

So he includes Go in a list of languages that apparently makes development slow and have “a build system that fought you” and then says python was the solution for all that. I think he got it backwards. I have found the Python build system horrific and broken by default while Go just works.

asdfftoday at 1:38 AM

Better question is why use any code? Generate random functions and select based on measuring the distribution of output of these functions against metrics of interest. A pure black box of instruction that is more performant than any verbose code or algorithm we could come up with, because all we select for is performance above all. Directed evolution essentially of the codebase, generated through mutation and selection, just like everything else on planet earth.

show 1 reply
nextlevelwizardtoday at 5:16 AM

Because there is no negatives, only positives.

I can maintain the Python code myself and I can execute it everywhere.

If I let my LLM write in Rust then when things break I am out of luck. Also Rust needs to be compiled which means I can't just share the code as freely.

show 1 reply
blululutoday at 6:26 AM

I'm sure there are plenty of caveats and breaking points, but if we do adhere to the claim that an LLM coding tool is a nondeterministic sort of compiler then it really does make sense to pick the most performant language available. Obviously there are caveats of libraries and native advantages of various languages. I've been doing stuff in C++ for the past month or so and the only slow down from the language choice is compilation time.

munroyesterday at 9:31 PM

Lately I just have Claude build most things in Rust, it's really amazing. I tried Go, but I found it wasn't as good--Rust really does to me feel like Python. That said, it still struggles with the same class of errors of building complex systems. I've tried using TLA+, Alloy, and other things but haven't found the trick yet. The best I've found is reimplementing all external systems in memory and e2e testing everything extensively, without reimplementing the tests become unusably slow, and Claude can rewrite huge surface areas with ease--it's somewhere between mocking and literally just reimplementing the external systems.

schmookeegyesterday at 9:08 PM

I assume this is why things like PyO3 are popping up? If so, sort of a fascinating way to compartmentalize new rust code into legacy .py code in lieu of a refactor, or at least, a way to do a staggered refactor and eat the elephant in bites :)

Havoctoday at 8:09 AM

I use a mix of both to try and leverage their advantages.

Rust in most cases, especially for back end.

Python when it's low risk (say monitoring dashboard or similar API heavy) or plays to python strengths (e.g. ML/AI - everything ML seems to be python).

tabbotttoday at 4:44 AM

I think the author misunderstands what is good about Python.

One of the big strengths of Python is legibility: most developers find it easy to read and understand.

If you are planning to have humans verify the code you're using in production, to confirm it implements your intent, the readability of the code you are producing is important.

Performance is valuable, but for a lot of code, performance is less important than correctness and ease of verifying it.

If you are imagining your codebase being one where nobody but Claude reads the code, you might as well do Rust for the better performance. But I don't think a lot of organizations are doing that.

tomashmtoday at 8:28 AM

And with AI writing code, why use libraries, which makes us more vulnerable to 0-day attacks?

Our simulation core components are pure Fortran, no libraries, all written by Claude/Cursor/Codex.

show 2 replies

🔗 View 50 more comments