Live data from Hacker News

If AI writes your code, why use Python?

medium.com

841–850 of 1001 posts

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

#841

Earlier quoted context omitted.

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.

Ironically it also created a ton of really badly written Python in the process.

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

#843

Earlier quoted context omitted.

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

Name one of those abstractions that is missing in Python.

You joking?

- strong typing - real concurrency (heaven forbid you want a background task without having to spool up an external message queue and worker) - immutability - limitations in error handling (sort of just typing really) - limitations in nullability (also typing) - memory layout is usually hidden or abstracted away - no actual private methods or classes

That's far from a complete list, but maybe you're taking for granted the typical pythonic conventions that many practice. It requires a ton of work to design and architect python systems of any non-trivial size for maintainability and understanding. No language is perfect, but there are plenty of languages that make supporting complex systems easier than python.

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

#844
post #787

Earlier quoted context omitted.

> Code readability of Python isn't an advantage during write; it's an advantage while reviewing. This is completely subjective though. I personally find that Python's lack of static types makes code very difficult to reason about. Yes, some devs will write decent comments and name things in a way that's easier to read, but most devs are lazy (myself included) and things get out of hand quickly. But this is also a sub…

Python has type annotations now [1] that type checkers, IDEs, etc. can use. [1] https://docs.python.org/3/library/typing.htmlhttps://docs.py...

Yes, but: a) they're a second class citizen, not guaranteed to be used in whatever niche of the python ecosystem you find yourself in and there's already an n+1 problem with multiple type checker written by third parties, rather than having 1st class language support tool that's consistent. You're not going to get it by default, you're usually going to have to do some configuration (and maybe bike shedding) to get it working; b) they completely negate the idea of python being "easy to read", your code is now littered with `if TYPE_CHECKING:`, `Literal`, `TypeAliasType` and any number of workarounds needed to make your hints work out. Unfortunately the syntax was just not designed with typing in mind, and I think it shows; c) the idea of "hinting" rather than enforced type checking means you have no guarantees that a type is what you need it to be, you have to do a lot of boundary work to make sure the edges of your code are coercing things to the right type. While I love pydantic and find it to be an excellent library, to me it's the kind of code smell you get in languages without strong typing. Also you're going to get a lot of spurious type errors along this path as well;

I will gladly use python's type hints, it's a whole lot better than nothing (IMHO better than typescript), but in it's current form it will always fall short of a language that was designed with strong typing in mind.

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

#845

The static vs dynamic language debate is decisively over and static has won. I called this out back in 2023, and I've only become more convinced since then. Statically typed languages are easier for the reader because you can see the types and quickly jump to their definitions (or even just hover over them in some IDEs). They're easier for the AI because they provide natural guardrails and feedback to guide it, as we…

[deleted]

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

#846

Earlier quoted context omitted.

> Algorithms written in "pseudo-code", aka a higher level language without type information, are far more readable to a human, and thus likely an LLM too. What’s the basis of this claim? There are many many more lines of code LLM’s are trained versus pseudo-code. Also I agree, anecdotally the self-correction is key benefit from static types. If there is a mistake, it is caught at compile time and not at runtime.

It seems clear to me from first principles. Humans are trained on human language. LLMs are trained on human language. Thus something that is easier for a human to understand is likely easier for an LLM to understand. That higher level language with well named variables reads more comprehensibly than code:VERB with:PREPOSITION types:NOUN, intermixed:ADJECTIVE, stems:VERB from:PREPOSITION first:ADJECTIVE principles:NOU…

As far as the AI is concerned, it's more like

Buffalo buffalo Buffalo buffalo buffalo buffalo Buffalo buffalo

versus

Buffalo:PN buffalo:N Buffalo:PN buffalo:N buffalo:V buffalo:V Buffalo:PN buffalo:N

I think the second one makes much more sense.

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

#847

The static vs dynamic language debate is decisively over and static has won. I called this out back in 2023, and I've only become more convinced since then. Statically typed languages are easier for the reader because you can see the types and quickly jump to their definitions (or even just hover over them in some IDEs). They're easier for the AI because they provide natural guardrails and feedback to guide it, as we…

If static has won, why are dynamic languages more popular now (even since 2023). Comically, I’ve witnessed people say this since the 90s. For me, I don’t care about static because dynamic is easier. For the very few conditions where it matters, I’ll use static. Otherwise I like the simplicity of dynamic languages, especially python. IDEs provide support and jump to definitions in dynamic languages, too.

I was on team dynamic for a long time and have moved to team static.

For any long-lived code base, dynamic piles up invisible problems over time.

It's great for short-lived throwaway stuff, but as soon as you know you'll be maintaining a large code base for a long time, the "easier" part of dynamic actually becomes harder than just spelling stuff out.

It's obviously a trade-off and not everyone agrees, but that's my personal experience having run large eng teams for both types.

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

#848

Earlier quoted context omitted.

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.

Although it's not part of core Python, tach is pretty handy for specifying and enforcing those larger-scale interactions: https://github.com/tach-org/tach

Yeah, that's cool, but it would be almost completely unnecessary if python just had actual private methods/classes/properties. It's a lot like pydantic, which is completely unnecessary if you had strong typing.

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

#849
post #75
post #29

Earlier quoted context omitted.

Problem with Python and other non-strict typed languages is that if you let an LLM to write some stuff, you cannot truly be confident that nothing has broken. Even if your tests all pass. The LLM could have broken some path that only gets run in production in a very specific case. At least with strongly-typed languages you get a compiler error. In big codebases is non-negotiable

Python has had type hinting for quite a while, and adding validation with mypy/pyright/ty as a step in CLAUDE.md (as well as having it as part of your CI pipeline) can emulate static type checking pretty well.

True, but in my experience teams don't make the whole codebase type hinted. There's always something that escapes.

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

#850

Earlier quoted context omitted.

If you are messing up indentation accidentally during refactoring there is either something wrong with your tooling (including your text editor) or you are letting things get too far out of hand before starting the refactoring.

It's 2026. I'm using Jupyter notebooks in Databricks. Guess what my tooling (including my "text editor", the Jupyter notebook), does not do? Yes, I can castle-[ to shift a block of code left or right, but this is not always problem-free nor is it automatic nor does it have any sense of where the indents should go. Yes, there is a "format python properly" button which often errors out says "there is an indentation err…

Does your tooling not allow you to select multiple lines of code and press Tab or Shift-Tab to indent/dedent the entire block?

It usually only takes me a 1-5 seconds to fix the indentation when I copy/paste code that existed at a different indentation level. This is not something I'd complain about, personally.

Post reply on HN