Hacker News new | ask | show | jobs
by jack_pp 1 day ago
Why would you write PHP with LLMs? The whole point of PHP / laravel is trading performance for speed of development. LLMs inherently solve speed of development so why even use PHP any more unless you're supporting a legacy code base?

I've worked on a single laravel project in the past and I didn't like it. Whenever I needed something just a little more complex than what the docs suggested I felt I had no way of figuring out how to do it and support forums were scarce of solutions.

6 comments

For the same reason you would build something in React in the LLM era... because it's what the LLMs are good at. What Laravel has going for it is that it's opinionated, those opinions are conventions (loosely) and that is consistency. That results in llms being very good at building laravel things the laravel way.

In the same way they're great at building things on React.

But I don't know, I'm just some rando who built a whole huge ass "factory" (that would be an understatement) on Laravel, for mostly (albeit, here lately, mostly not) Laravel projects and it's _insane_. I may be biased. I may also be lucky to have jumped on that bandwagon.

And why follow it to Rust/Go? Same reason. The opinionated wave of consistency and quality into languages with different strengths.

> you would build something in React in the LLM era... because it's what the LLMs are good at

LLMs are very good at rust / go too. Rust / Go are also a lot more performant than php / laravel

> And why follow it to Rust/Go? Same reason

except if you want performance and decide to go for Rust / Go then LLMs wouldn't have been trained on laravel for rust / go because it's new so you'd be better off using an old framework.

LLMs do not care. I have written my own language/repl/vm in C3, and an AI generates my own language just fine. Its a totally new language, new syntax with semi general semantics (its basicallt go channels on an beam like runtime) that have (and will always have) one user, me.
Who guarantees that LLMs will generate code that fulfils quality and security requirements? A human still has to be responsible for the resulting product and when the human can't follow what the AI does, it is worthless. For a human to follow the AI results he has to read and understand the code, which brings us back to a well documented framework that helps to follow along.
> Whenever I needed something just a little more complex than what the docs suggested I felt I had no way of figuring out how to do it and support forums were scarce of solutions

Details ?

Laravel docs & ecosystem are top-shelf

Laravel docs are the best I've ever encountered in the web dev business.
> The whole point of PHP / laravel is trading performance for speed of development.

(For my 12-year-old self, it was being able to push a bunch of .php to a free host and have them run. I later even considered learning Haxe to have a better language while still being able to compile to PHP for that use case.)

Just ask the LLM to output assembly directly then. As long as nobody ever has to answer questions about the code, it'll be ok.
On the other hand, why would you prefer any human-readable programming language or framework over another in the age of LLMs?

Like, why stop at Rust or Go when LLMs will soon be able to generate binaries for your target architecture better than any compiler can. The LLM could be writing dark verses in brainfuck behind the scenes for all I know. It doesn't matter anymore because we're not gonna read any of it.

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.

> 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.

Why drive a car when you can teleport in the future?
Introducing BFCode... the Brainfuck llm you didnt know you needed