Hacker News new | ask | show | jobs
by preg_match 21 hours ago
Because they won’t be able to write assembly well. LLMs rely on strong guardrails and tools to perform well.

PHP performs poorly with LLMs not because it’s readable, but because it’s too dynamic and wishy-washy. Statically typed languages and strongly typed languages just perform better out of the gate, because the LLM has more context to reason about the code.

I program in PHP all day, I know. PHP is a bad language for LLMs. C# is better, Java is better, rust is better. LLMs will never replace compilers because they don’t need to. What compilers provide is a rich information system and strict structure. That’s exactly what LLMs rely on.

3 comments

> Because they won’t be able to write assembly well.

They already do a good enough job, it is only a matter of improving it.

https://www.phoronix.com/news/Frame-X11-Server-Assembly

They do a piss-poor job as compared to the output of compiled languages. The assembly will be slower and more buggy, because assembly has no guardrails.

A type system and compiler is for correctness. Using them results in higher quality software. There’s just zero reason to have an AI write assembly. Unless it’s tiny pockets of ultra-optimized assembly in, say, a decoder.

Think of it this way. The mere fact a compiler exists allows the LLM to use 1/10 of the tokens to get the same result. Instead of constantly iterating through the logic in its context and trying to figure out what’s going on, it can rely on the compiler, which is deterministic, to help it.

LLMs are not much different from human programmers when it comes to seeing new code. If you were onboarding into a new codebase, with no context, would you prefer assembly, PHP, or dotnet? Dotnet first, PHP second, assembly last. Dotnet has more context in the code itself, so you can reason about it quicker, easier, and more accurately.

> I program in PHP all day, I know. PHP is a bad language for LLMs. C# is better, Java is better, rust is better

I also work in PHP with LLMs and have no idea what you're talking about

You should try out other languages and you’ll see the difference. LLMs hallucinate array keys that don’t exist, program extremely defensively (?? fucking everywhere) and make trivial type mistakes. It doesn’t see, or forgets, that a string was converted to a DateTime 500 lines earlier and then makes a mistake.

The LLM has almost no guardrails to fall back on. The best is php -l and unit tests. It has to reason about the code from scratch every time, and in doing so it makes mistakes and wrong assumptions. That’s much less of a problem in other languages.

> You should try out other languages and you’ll see the difference

I do? I work in several languages. Nothing has stood out about PHP that is worse for LLM reasoning. It's one of the most widely used languages in the world, it obviously performs pretty will with LLMs.

What languages are you working in?

> LLMs hallucinate array keys that don’t exist

I use data objects, which are typed. PHP has types, did you not know that? If you're using raw dynamic arrays, yeah, an LLM might hallucinate keys with enough context rot. That is true of any dynamic syntax, and using raw arrays hasn't been standard practice in quite some time.

> It doesn’t see, or forgets, that a string was converted to a DateTime 500 lines earlier and then makes a mistake

I don't know man, this is not remotely close to my experience. Unless you were doing this like 2 years ago when LLMs were an entirely different beast. That's the only explanation I can think of for your LLM being incapable of reading 500 lines of PHP code.

> It has to reason about the code from scratch every time, and in doing so it makes mistakes and wrong assumptions

This sentence makes less sense the more I read it. What about PHP do you think makes LLMs "reason from scratch every time"?

> PHP has types, did you not know that?

Yes I know that, please don't be an asshole. As I've said I work on a 10 million line plus PHP monolith every day. Yes, arrays are used extensively, we don't use classes for everything.

Classes also don't save you, because classes are just arrays with more steps. You can absolutely dynamically add properties to classes. Should you? No. In a legacy codebase that's 20+ years old do people do that? yes.

> That's the only explanation I can think of for your LLM being incapable of reading 500 lines of PHP code.

There's a lot of other stuff going on in those 500 lines. It's not like 500 lines of code translates into 500 lines worth of tokens. And you know that!

The LLM has to reason and think about the code. 500 lines of code could be enough to pollute the context enough.

> What about PHP do you think makes LLMs "reason from scratch every time"?

The fact that if you want to understand parts of the behavior, you have to read the code. The type system is too weak. The semantics too flexible.

Consider the following:

    function someFunc(): array
    {
      ///... some hundred lines of code, nesting, etc
      $date ??= '';
    }

Is date defined here? What's the type of date? Is it a datetime, an array, a string, what? In every other language, you would know just by reading that singular line. In PHP, you can't. You need to read the entire function.

What if $date was set 3 levels of nesting deep? It's function-scoped, so now it's defined. Now we have to reason about what runtime conditions can cause $date to be defined or undefined?

In C#, you don't have to do that reasoning. At all.

That's ONE tiny feature of PHP that makes it harder to statically analyze. ONE. There's hundreds of PHP features like this that just don't exist in other languages. Dynamic includes are another. I have seen classes that light up like a christmas tree in the editor. Errors, which should be criticals, everywhere.

But guess what. The class works and isn't buggy. That's not even possible in 99% of languages. But in PHP, it is, because we're including random files in different code paths and that's defining and setting variables for us.

Each of these features is, in it of itself, bad for static analysis and therefore bad for LLMs. But when you combine them together, it gets worse, more than the sum of its parts. Because now there are permutations, combinations of evil things.

PHP is just not a good language for LLMs, period. It's my experience in a very large codebase, which I can almost assure you is larger and more complex than whatever you're working on. It MIGHT work if you only stick to the most modern features and work in small codebases with tightly defined conventions. It does not work in the applications I work on. Well, I mean, it works, but just obviously not as well as dotnet or Java.

> I program in PHP all day, I know. PHP is a bad language for LLMs.

That statement is so absurdly false that I'm fully convinced you never used an LLM for serious PHP development.

I use an LLM every day on a codebase that’s at least 10 million lines long.

LLMs perform poorly in huge monoliths (not enough context) and they perform poorly in PHP (not enough context in the code). It’s just intrinsic to how LLMs work.

Can you explain what about PHP has less context? Are you working in a PHP codebase with no types?
Even with types the code does not have enough context.

You can type a variable as array. Now what's in? You don't know unless you read a lot of code.

You can type a variable as a class. Now what's in it? You still don't know, because properties and methods may be dynamically added in various code paths. What methods can you call on this class? You don't know, because it uses magic methods for resolution.

You see a variable in a function. Is it defined? What's it's value or type? You don't know, because there are no local types in PHP. And you don't know if the variable is defined because it could have been defined 3 layers of nesting deep in the function. You have to read more code to find out.

You call a function. Is it defined? You don't know, because it could have been included in an include() somewhere else in the class or function.

You just have to read 10x as much code to get the same amount of context that a language like C# gives you for free via the compiler.