Live data from Hacker News

If AI writes your code, why use Python?

medium.com

731–740 of 1001 posts

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

#731

Earlier quoted context omitted.

hmm, yeah given LLM's ability to churn out lots of code quickly and be overly verbose in that code that is a potential downside. That it could in a quick one time edit create so much intellectual overhead that Python might be the wrong language to understand what is going on. What language do you feel is easier to reason about in the large?

Haskell would be my vote, and Rust too, actually, both because of their very strong type systems. The type system lets you very quickly figure out what something is before you figure out what something does , and it turns out that separating those two concerns as hard as those two languages do often results in doing the whole one-two punch faster.

I’d add perl (similar runtime semantics as python, but at least sigils give you some hint of developer intent. If you see &@%$$ck() in perl, you know you’re in for a ride).

I’d also add, C, C++, Rust, Java, Swift, Typescript, Ruby, Lisp, Make, Awk and Sed.

The only thing I’d rate a tie is Javascript.

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

#732
post #708
post #649

Earlier quoted context omitted.

What if you want to offload a lot of the work to libraries rather than generating (and presumably reviewing?) it yourself? Python has a very strong ecosystem of useful libraries because it's been around so long and is popular in a number of application domains.

You could use Scala, get the strong typing, but also get access to the Java and also Python/JS libraries and others via various interop mechanisms Java has.

And you also get compile times so long you’ll never run out of tokens!

I kid, I kid, but seriously …

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

#733

Earlier quoted context omitted.

What study? And I don't see how Go design patterns would be any worse. The main issue people have with it is the repetition/verbosity, which LLMs handle just fine.

The repetition and verbosity makes it more expensive for the LLM to write. You'd want a language that is expressive and dense if you're optimizing for token usage.

APL would seem to be perfect!

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

#734

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…

I personally don’t find it readable at all.

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

#735

Earlier quoted context omitted.

The tools the language gives you to create those abstractions make a lot of difference, however.

But every abstraction that an LLM has to write is a choice. Your way of writing Python may not match that choice. The next run of the agent might not choose the same way. Because the language gives you many different tools, an LLM generated codebase can get inconsistent and overly complicated quickly. The flexibility of Python is a downside when you’re having an LLM generate the code. If you’re working in an existing…

That’s why proper using LLMs on large python codebases establish coding standards docs and tests. Turning the LLM loose is chaos, but having clear arch and naming and other standards can get pretty consistent results.

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

#736

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…

Less verbose languages also use fewer tokens, saving precious context.

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

#737

Earlier quoted context omitted.

>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. I find this staggeringly hard to believe. Most bugs are logic errors. How does Rust or Haskell prevent these?

> Most bugs are logic errors. Are they? IME most bugs are type errors. Or rather, IME most bugs are logic errors only because I've excluded the possibility of type errors by using a sophisticated type system.

Most of my bugs are logic errors. I write Java. Your comment seems to imply that moving to Rust or Haskell would make a correct program if it compiles.

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

#738

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/

If you use the typing system (which I do religiously) Python becomes a lot easier to reason about in larger projects it also makes linters and refactoring tools easier to use.

Maybe I'm just using it wrong, but typed Python seems a long way behind typed JS (i.e. TypeScript).

In Python in seems like there are multiple type-checkers with widely differing levels of coverage, so it's not at all obvious which one to use, and typing is really spotty in third-party libraries. So you can get some level of type-safety but it doesn't feel very dependable.

In TS, there's one canonical checker and the others work hard to stay compatible with it; and typing in third-party libraries is generally very solid. There are still some old libraries without types, but I think those headaches are mostly in the past now (similar to the Python 2 -> 3 switch).

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

#739

Earlier quoted context omitted.

> Most bugs are logic errors. Are they? IME most bugs are type errors. Or rather, IME most bugs are logic errors only because I've excluded the possibility of type errors by using a sophisticated type system.

Most of my bugs are logic errors. I write Java. Your comment seems to imply that moving to Rust or Haskell would make a correct program if it compiles.

I don't think porting your program to Haskell would make your program correct.

I think porting your program to Haskell would make all of your bugs logic errors, rather than only most of them.

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

#740

Earlier quoted context omitted.

Reaaaally? I think a lot of the readability of python is in the fact you don't need to be recently familiar with it to pick up what its doing most of the time. Over my career I've dipped in and out of rust, typescript, perl, swift, etc codebases. I'm no expert in any of these, but every single time I have to look something up to understand what this set of arcane symbols or syntax means. When I dip into Python I just…

I dunno, as someone who doesn't program in Python, I find dunders to be very confusing. Like, how is this readable? _foo foo_ __foo _Foo__bar __foo__ foo__bar All of that is valid Python, and some of those forms mean different things depending on where they are used.

What do you mean? Those are valid identifiers but programmers aren't required to use them.
Post reply on HN