Live data from Hacker News

Can LLMs write better code if you keep asking them to “write better code”?

minimaxir.com

221–230 of 461 posts

Re: Can LLMs write better code if you keep asking them to “write better code”?

#221
post #195
post #170

Earlier quoted context omitted.

> I wish people would understand what a large language model is. I think your view of llm does not explain the learning of algorithms that these constructs are clearly capable of, see for example: https://arxiv.org/abs/2208.01066 More generally, the best way to compress information from too many different coding examples is to figure out how to code rather than try to interpolate between existing blogs and QA forums.…

To the downvoters: I am curious if the downvoting is because of my speculation, or because of the difference in understanding of decoder transformer models. Thanks!

Because you cite is about:

> in-context learning

LLMs have no concept of the symantic meaning of what they do, they just are dealing with next token prediction.

"in-context learning" is the problem, not the solution to general programming tasks.

Memoryless, ergodic, sub Turing complete problems are a very tiny class.

Think about how the Entscheidungsproblem relates to halting or the frame problem and the specification problem may be a path.

But that paper isn't solving the problem at hand.

Re: Can LLMs write better code if you keep asking them to “write better code”?

#222

I've noticed this with GPT as well -- the first result I get is usually mediocre and incomplete, often incorrect if I'm working on something a little more obscure (eg, OpenSCAD code). I've taken to asking it to "skip the mediocre nonsense and return the good solution on the first try". The next part is a little strange - it arose out of frustration, but it also seems to improve results. Let's call it "negative incent…

We've entered the voodoo witch doctor phase of LLM usage: " Enter thee this arcane incantation along with thy question into the idol and, lo, the ineffable machine spirits wilt be appeased and deign to grant thee the information thou hast asked for. "

This has been part of LLM usage since day 1, and I say that as an ardent fan of the tech. Let's not forget how much ink has been spilled over that fact that "think through this step by step" measurably improved/improves performance.

Re: Can LLMs write better code if you keep asking them to “write better code”?

#223
This makes me wonder if there’s conflicts of interest with AI companies and getting you the best results the first time.

If you have to keep querying the LLM to refine your output you will spend many times more in compute vs if the model was trained to produce the best result the first time around

Re: Can LLMs write better code if you keep asking them to “write better code”?

#224
post #137

Earlier quoted context omitted.

There's another, arguably even simpler, optimization that makes me smile. (Because it's silly and arises only from the oddity of the task, and because it's such a huge performance gain.) You're picking 1,000,000 random numbers from 1 to 100,000. That means that any given number is much more likely to appear than not. In particular, it is very likely that the list contains both 3999 (which is the smallest number with…

This is actually a great example of an optimization that would be extremely difficult for an LLM to find. It requires a separate computation to find the smallest /largest numbers in the range with digits summing to 30. Hence, an LLM is unlikely to be able to generate them accurately on-the-fly.

I tried it in OpenAI's O1. If I give it minimaxir's original prompt it writes the obvious loop, even if I include the postamble "Look for tricks that will make this function run as fast as possible in the common case".

However, if I then simply ask "What is the most probable result for this function to return?" it figures out the answer and a very good approximation of the probability (4.5e-5). From there it's easily able to rewrite the program to use the trick. So the creative step of spotting that this line of reasoning might be profitable seems missing for now, but 2025's models might solve this :-)

Re: Can LLMs write better code if you keep asking them to “write better code”?

#225

Earlier quoted context omitted.

>I often run into LLMs writing "beginner code" that uses the most fundamental findings in really impractical ways. Trained on too many tutorials I assume. In the absence of any other context, that's probably a sensible default behaviour. If someone is just asking "write me some code that does x", they're highly likely to be a beginner and they aren't going to be able to understand or reason about a more sophisticated…

In my experience the trouble with LLMs at the professional level is that they're almost as much work to prompt to get the right output as it would be to simply write the code. You have to provide context, ask nicely, come up with and remind it about edge cases, suggest which libraries to use, proofread the output, and correct it when it inevitably screws up anyway. I use Copilot for autocomplete regularly, and that's…

It depends on what you’re doing. I’ve been using Claude to help me write a web admin interface to some backend code I wrote. I haven’t used react since it first came out (and I got a patch randomly in!)… it completely wrote a working react app. Yes it sometimes did the wrong thing, but I just kept correcting it. I was able in a few hours to do something that would have taken me weeks to learn and figure out. I probably missed out on learning react once again, but the time saved on a side project was immense! And it came up with some pretty ok UI I also didn’t have to design!

Re: Can LLMs write better code if you keep asking them to “write better code”?

#226
post #167

Earlier quoted context omitted.

Suggestion: Now take the code away, and have the chatbot generate code that passes the tests it wrote. (In theory, you get a clean-room implementation of the original code. If you do this please ping me because I'd love to see the results.)

That’s sort of interesting. If code -> tests -> code is enough to get a clean room implementation, really, I wonder if this sort of tool would test that.

I don't think it is, but I'm really interested to see someone try it (I'm also lazy).

(And a more philosophical question: if it's not enough, what does that mean for continuous deployment?)

Re: Can LLMs write better code if you keep asking them to “write better code”?

#227
post #207
post #119

Earlier quoted context omitted.

> There is no thinking. No comprehension. No decisions. Re-reading my own comment, I am unclear why you think it necessary to say those specific examples — my descriptions were "results, made, disagree, right/wrong, struggle": tools make things, have results; engines struggle; search engines can be right or wrong; words can be disagreed with regardless of authorship. While I am curious what it would mean for a system…

Re-reading my own comment, I am unclear why you think it necessary to say those specific examples Sorry to cause unneeded introspection, my comment was sort of thread based, not specific in whole to your comment.

Introspection is a good thing, and I tend to re-read (and edit) my comments several times before I'm happy with them, in part because of the risk autocorrupt accidentally replacing one word with a completely different werewolf*.

Either way, no need to apologise :)

* intentional

Re: Can LLMs write better code if you keep asking them to “write better code”?

#228
post #195
post #170

Earlier quoted context omitted.

> I wish people would understand what a large language model is. I think your view of llm does not explain the learning of algorithms that these constructs are clearly capable of, see for example: https://arxiv.org/abs/2208.01066 More generally, the best way to compress information from too many different coding examples is to figure out how to code rather than try to interpolate between existing blogs and QA forums.…

To the downvoters: I am curious if the downvoting is because of my speculation, or because of the difference in understanding of decoder transformer models. Thanks!

Probably the latter - LLM's are trained to predict the training set, not compress. They will generalize to some degree, but that happens naturally as part of the training dynamics (it's not explicitly rewarded), and only to extent it doesn't increase prediction errors.

Re: Can LLMs write better code if you keep asking them to “write better code”?

#230
post #5

Something major missing from the LLM toolkit at the moment is that it can't actually run (and e.g. test or benchmark) its own code. Without that, the LLM is flying blind. I guess there are big security risks involved in making this happen. I wonder if anyone has figured out what kind of sandbox could safely be handed to a LLM.

Ideally you could this one step further and feed production logs, user session replays and feedback into the LLM. If the UX is what I'm optimizing for, I want it to have that context, not for it to speculate about performance issues that might not exist.
Post reply on HN