Hacker News new | ask | show | jobs
by ChrisMarshallNY 21 days ago
I program in two languages: Swift (my main language), for client work, and PHP, for backend work. It’s overwhelmingly Swift.

In the last year or so, I have been using LLMs, to assist my work, with generally, excellent results.

I have noticed that the LLM delivers much better PHP, than Swift. I seldom need to rewrite or correct, the PHP code I get from it, and am constantly correcting the Swift. Part of the reason, may be that I am a much better Swift programmer, than PHP programmer, and there’s just a lot more Swift code. I haven’t really taken the time to analyze it.

I have my theories, as to why, but it’s not something I’m really into researching. I’ve just noted the trend.

3 comments

I think it's pretty simple - there's just so much more open source PHP code out there in the LLM's training dataset. Swift has been around for much less, and most Swift is closed-source - not that many years have passed since Swift has been able to run on non-Apple platforms, too.
PHP changed a lot since its early days. To the point where anything old would be considered bad practice by contemporary ecosystem point of view. So duration is not all. Comparatively, C seems to have stick to the same idiom all the way. That's not to praise C style form here to be clear, which is ridiculously obfuscating and feeling like pointless collection of linguistic awkward atrocities. But at least it's consistent in doing it.
I would also bet that 90% of Swift training data is UI code.

And UI code quality tends to be technically pretty crummy/low-discipline. Your UI code doesn't need much consideration around data races, for example.

You wouldn't know that, if you looked at the UI code the LLM gives me. It loves threads; often mixing GCD and async/await, in one function.

A lot of the code I need to tear out, looks like that.

Most of the code I write is UI. It's actually fairly intense work, but relies on the underlying SDK, rather than language tricks.

I find the UIKit code I get, is a lot more robust and performant, than the SwiftUI code.

> I have noticed that the LLM delivers much better PHP, than Swift.

If you ever have the time and inclination to try Axiom (https://charleswiltgen.github.io/Axiom/), I'd really appreciate knowing if you feel it quantitatively changes the Swift experience with your LLM/coding harness of choice, especially in regards to Swift concurrency.

Looks like a labor of love.

Honestly, not sure that I'll be able to use it, right now (no telling, in the future). Looks like you really did a good job, though!

> Part of the reason, may be that I am a much better Swift programmer, than PHP programmer

Hard not to think that's a major part of it. IME you make loads more corrections in languages you're more opinionated about (and opinionated usually follows more experience & confidence).

I correct AI Python all the time. When it cranks out TypeScript I just check it works.

Yes and no. I have been working with PHP for over 25 years, but I've never loved the language. It's always been a "necessary evil." I know it fairly well. I've only been writing Swift for half that time, but I like the language, and play with it more.

I feel that the reason posited by another poster is more likely. There's a ton of mature, well-written, shipping, PHP out there, due to the open nature of most PHP, as opposed to Swift; where the more robust and mature implementation is likely behind proprietary walls. Most of the public Swift that I see, tends to be folks showing off its fancier features, in relatively small code samples.