Live data from Hacker News

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

minimaxir.com

91–100 of 461 posts

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

#91
post #14
post #12

So asking it to write better code produces code with errors that can’t run?

Only when there's a financial incentive.

Makes sense. If I was paid by LOC and also responsible for fixing it, I’d probably make lots of errors too.

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

#93

Using the tool in this way is a bit like mining: repeatedly hacking away with a blunt instrument (simple prompt) looking for diamonds (100x speedup out of nowhere). Probably a lot of work will be done in this semi-skilled brute-force sort of way.

Once you can basically have it run and benchmark the code, and then iterate that overnight, it’s going to be interesting.

Automating the feedback loop is key.

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

#94
post #77

Earlier quoted context omitted.

You can write maximally modular code while being minimally indirect. A well-designed interface defines communication barriers between pieces of code, but you don't have to abstract away the business logic. The interface can do exactly what it says on the tin.

> The interface can do exactly what it says on the tin. In theory. Do some code maintenance and you'll soon find that many things don't do what it says on the tin. Hence the need for debug and maintenance. And then going through multiple levels of indirection to get to your bug will make you start hating some "good code".

Yes, that's what can means. It's still the developer's responsibility to correctly write and test code such that things do what they say on the tin.

What's worse is trying to navigate an imperatively written 2000-line single-function, untestable module with undocumented, unabstracted routines found in ten other places in the codebase.

This is something I've encountered plenty in my career, always written by people who eschew best practices and misunderstand the benefits of abstraction, or think they're writing good abstractions when it's really just needless indirection without actually reducing coupling.

Understanding the nuance is one of the qualities of a good developer.

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

#95
post #92

This aligns with my experience. Claude very quickly adds classes to python code which isn't always what is wanted as it bloats out the code making readability harder.

I wonder how they’ll get around the model producing “average,” (mediocre) outputs? Perhaps quantity?

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

#96
post #92

This aligns with my experience. Claude very quickly adds classes to python code which isn't always what is wanted as it bloats out the code making readability harder.

tell this to half the devs out there who view this as clean code because uncle bob says so.

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

#97
As far as I can see, all the proposed solutions calculate the sums by doing division, and badly. This is in LiveCode, which I'm more familiar with than Python, but it's roughly twice as fast as the mod/div equivalent in LiveCode:

   repeat with i = 0 to 9
      put i * 10000 into ip
      repeat with j = 0 to 9
         put j * 1000 into jp
         repeat with k = 0 to 9
            put k * 100 into kp
            repeat with l = 0 to 9
               put l * 10 into lp
               repeat with m = 0 to 9
                  put i + j + k + l + m into R[ip + jp + kp + lp + m]
               end repeat
            end repeat
         end repeat
      end repeat
   end repeat

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

#98

Using the tool in this way is a bit like mining: repeatedly hacking away with a blunt instrument (simple prompt) looking for diamonds (100x speedup out of nowhere). Probably a lot of work will be done in this semi-skilled brute-force sort of way.

Once you can basically have it run and benchmark the code, and then iterate that overnight, it’s going to be interesting. Automating the feedback loop is key.

Wouldn't there be some safety concerns to letting the AI run overnight with access to run any command?

Maybe if it can run sandboxed, with no internet access (but if the LLM is not local, it does require internet access).

Post reply on HN