Live data from Hacker News

If AI writes your code, why use Python?

medium.com

681–690 of 1001 posts

Re: If AI writes your code, why use Python?

#681

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…

Python is locally readable. Reasoning about larger systems in Python is where things get really hard, because you have to describe how many small individually readable things interact with each other in a very limited vocabulary.

This is why good design documents will always be necessary.

When I work with AI I always have it keep an up-to-date architectural document committed to the repository.

Also, we need to be able to understand what is happening under the hood somewhat, so I very much agree the readability is crucial. And frankly, rust is not up there in the readability realm.

I think all the previous language designs still hold for their respective use case. AI written or otherwise. Why? Because performance acceptability is domain specific, and also the algorithms complexity generally determines overall performance.

For example, move the performance critical stuff into a Python C extension like Torch etc…

Re: If AI writes your code, why use Python?

#682
post #479

Earlier quoted context omitted.

I never really understood what exactly is so readable about python. I've been developing in Python for 8 years now, and before that I was a C# developer, and I don't find Python to be that more readable. Sure there's less ceremony, and yes, you can have your project going with just a single file, but other than that...?

I think the meme come from the fact that in 00s and early 10s most people looked at Python code coming from C++ and Java. In Java bad OOP conventions were commonplace, like everything using getters/setters, deeply nested class hierarchies and insane patterns like AbstractSingletonProxyFactoryBean. It got impossible to figure out what's going on. C++ just got every possible feature that badly interacts with each other…

C++ and Java and … Perl.

Re: If AI writes your code, why use Python?

#683

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 languag…

>Lack of strictly enforced static typing make agents fail much sooner with Python. Just tell your agent "Use type hints. Add a pre-commit hook to run ruff, black, mypy, and pytest." It will save you 99% of headaches.

I've tested many flows involving linters. Results are far from ideal - agents tend to work around linters, mass-add ignore annotations, etc, especially in situations when fixing one warning/error triggers another (and that happens regularly).

Re: If AI writes your code, why use Python?

#684

Earlier quoted context omitted.

Python is amazing for scripting. Python is terrible for writing big systems. Projects whose V1 is written in Go/Rust/C++ don't normally go out and re-write V2 in Python. The reverse is really common. Even many famous Python packages are now Python wrappers. https://ashishb.net/programming/python-in-production/

> Projects whose V1 is written in Go/Rust/C++ don't normally go out and re-write V2 in Python. That's because you would usually rewrite your Python program in something like C++ if you realise that it's too slow and you need the speed of a compiled language, despite the enormous extra complexity to create and maintain it that way. You wouldn't go back the other way because it's very rare to go to all that extra effor…

That and how many developers who would write first round in Go/Rust/C++ would think it beneath them to write in Python :) The complaints alone wouldn't be worth it even if there was some suprising specific use case.

Re: If AI writes your code, why use Python?

#685

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…

Python is great at AI code gen for a combo of reasons: big stdlib, readable, 3rd party libraries to do most anything with great online documentation, big mind-share and presence online.

The big one to me is that it's interpreted. Claude Code does these wild `python -c` "one-liners" that end up spanning a hundred lines or more. It's so ingrained that it does this for solving general problems to create on-the-fly system reports, not just when you specifically are using it for Python development.

One of my more interesting experiments has been "mirroring" a Python codebase I maintain with a synchronized one in another language the AI maintains.

Re: If AI writes your code, why use Python?

#686
post #479

Earlier quoted context omitted.

I never really understood what exactly is so readable about python. I've been developing in Python for 8 years now, and before that I was a C# developer, and I don't find Python to be that more readable. Sure there's less ceremony, and yes, you can have your project going with just a single file, but other than that...?

I think the meme come from the fact that in 00s and early 10s most people looked at Python code coming from C++ and Java. In Java bad OOP conventions were commonplace, like everything using getters/setters, deeply nested class hierarchies and insane patterns like AbstractSingletonProxyFactoryBean. It got impossible to figure out what's going on. C++ just got every possible feature that badly interacts with each other…

Python data processing/ML in the 2010s became a huge asset for the language.

Re: If AI writes your code, why use Python?

#687
Because AI will only write the code, you have to read and maintain it. You can ask AI to write it in brainfuck too. But there would be a time (for sure) when AI will not be getting your point what exactly you want and you would be pulling your hair in frustration.

Therefore, write in what you can manage later.

Re: If AI writes your code, why use Python?

#688
post #464

Earlier quoted context omitted.

Agree. I am using type hints in Python as much as possible for my hand-coding. And it catches a lot of bugs (especially during code refactoring) that I would not have noticed so easily.

> And it catches a lot of bugs (especially during code refactoring) that I would not have noticed so easily. Can you give me an example of a recent experience with this? I've been working without type annotations for many, many years, and I keep finding that every time I find a bug I just don't feel like type annotations would have helped catch it, at least not to an extent that justifies the effort to put them in in…

I'm not sure how many bugs type hinting in Python finds.

But it is another guardrail that you are giving AI. When you have the AI use ty (and it runs almost instantaneously) after every edit, you are stacking the odds in you favor. There's no reason not to do this.

May the tokens ever flow.

Re: If AI writes your code, why use Python?

#690
Low bar critiques:

> For the last decade, fast-to-ship beat fast-to-run. Not anymore.

Fast-to-ship didn't beat fast-to-run, it was "beating" "quality built software." It still is. Beating here implying that it's the focus of companies.

> picked a harder, faster language

Go is absolutely an easier/simpler language than JS/TS.

> The Python ecosystem is increasingly a Rust ecosystem wearing a Python hat.

The Python ecosystem was just C/++ wearing a Python hat for years. I guess now it's C/++/Rust.

> The old defense of Python and TypeScript was really a defense of the developer experience.

Maybe for Python, but the TypeScript "defense" was always that there is a level of harmony to using the same language for front-end and back-end.

On the example used at the end:

> A shipped app, in a language nobody on the team knew, one-tenth the size of the Electron version, faster at runtime. The humans never had to learn Rust to get there.

Yeah and nobody knows or cares about the app, so it doesn't matter. Using products nobody will ever use as anecdotal evidence is not a great way to end an article filled marred with misunderstandings of the existing ecosystem and practices.

Post reply on HN