Live data from Hacker News

AI is forcing us to write good code

bits.logic.inc

81–90 of 229 posts

Re: AI is forcing us to write good code

#81
post #60

I thought that the article would be about if we want AI to be effective, we should write good code. What I notice is that Claude stumbles more on code that is illogical, unclear or has bad variable names. For example if a variable is name "iteration_count" but actually contains a sum that will "fool" AI. So keeping the code tidy gives the AI clearer hints on what's going on which gives better results. But I guess tha…

What I find works really well: scaffold the method signature and write your intent in the comment for the inputs, outputs, and any mutations/business logic + instructions on approach. LLM has very high chance of on shotting this and doing it well.

This is what I tend to do. I still feel like my expertise in architecting the software and abstractions is like 10x better than I've seen an LLM do. I'll ask it to do X, and then ask it to do Y, and then ask it to do Z, and it'll give you the most junior looking code ever. No real thought on abstractions, maybe you'll just get the logic split into different functions if you're lucky. But no big picture thinking, even if I prompt it well it'll then create bad abstractions that expose too much information.

So eventually it gets to the point where I'm basically explaining to it what interfaces to abstract, what should be an implementation detail and what can be exposed to the wider system, what the method signatures should look like, etc.

So I had a better experience when I just wrote the code myself at a very high level. I know what the big picture look of the software will be. What types I need, what interfaces I need, what different implementations of something I need. So I'll create them as stubs. The types will have no fields, the functions will have no body, and they'll just have simple comments explaining what they should do. Then I ask the LLM to write the implementation of the types and functions.

And to be fair, this is the approach I have taken for a very long time now. But when a new more powerful model is released, I will try and get it to solve these types of day to day problems from just prompts alone and it still isn't there yet.

It's one of the biggest issues with LLM first software development from what I've seen. LLMs will happily just build upon bad foundations and getting them to "think" about refactoring the code to add a new feature takes a lot of prompting effort that most people just don't have. So they will stack change upon change upon change and sure, it works. But the code becomes absolutely unmaintainable. LLM purists will argue that the code is fine because it's only going to be read by an LLM but I'm not convinced. Bad code definitely confuses the LLMs more.

Re: AI is forcing us to write good code

#82

Earlier quoted context omitted.

Pre-agents, 100% agree. Now, it's not a bad idea, the cost to do it isn't terrible, though there's diminishing returns as you get >90-95%.

The problem is that it is natural to have code that is unreachable. Maybe you are trying to defend against potential cases that may be there in the future (e.g., things that are yet implemented), or algorithms written in a general way but are only used in a specific way. 100% test coverage requires removing these, and can hurt future development.

It doesn't require removing them if you think you'll need them. It just requires writing tests for those edge cases so you have confidence that the code will work correctly if/when those branches do eventually run.

I don't think anyone wants production code paths that have never been tried, right?

Re: AI is forcing us to write good code

#83
post #8

Earlier quoted context omitted.

Can you say more? I see a lot of teams struggling with getting AI to work for them. A lot of folks expect it to be a little more magical and "free" than it actually is. So this post is just me sharing what works well for us on a very seasoned eng team.

it is MUCH easier for solo devs to get agents to work for them than it is for teams to get agents to work for them.

that's interesting, whats the reason for that?

Re: AI is forcing us to write good code

#84
post #13
post #6

Author should ask AI to write a small app with 100% code coverage that breaks in every path except what is covered in the tests.

Example output if anyone else is curious: def fragile(x): lst = [None] lst[x - 42] return "ok" def test_fragile(): assert fragile(42) == "ok"

this doesn't seem like a very useful test...? i'm more interested in the failure modes when input != 42, what happens when i pass NaN to that etc...

jmo, but tests should be a chance to improve the implementation of functions not just one-off "write and forget" confirmations of the happy path only... automating all that just short-circuits that whole process... but maybe i'm missing something.

Re: AI is forcing us to write good code

#85
post #35

I don't know about all this AI stuff. How are LLMs going to stay on top of new design concepts, new languages, really anything new? Can LLMs be trained to operate "fluently" with regards to a genuinely new concept? I think LLMs are good for writing certain types of "bad code", i.e. if you're learning a new language or trying to quickly create a prototype. However to me it seems like a security risk to try to write "g…

You do realise they can search the web? They can read documentation and api specs?

They can't think though. They can't be creative.

Re: AI is forcing us to write good code

#86

Earlier quoted context omitted.

it is MUCH easier for solo devs to get agents to work for them than it is for teams to get agents to work for them.

that's interesting, whats the reason for that?

Hi, the reason I have this expectation is that on a (cognitively) diverse team there will be a range of reactions that all need to be accommodated.

some (many?) devs don't want agents. Either because the agent takes away the 'fun' part of their work, or because they don't trust the agent, or because they truly do not find a use for it in their process.

I remember being on teams which only remained functional because two devs tried very hard to stay out of one another's way. Nothing wrong with either of them, their approach to the work was just not very compatible.

In the same way, I expect diverse teams to struggle with finding a mode of adoption that does not negatively impact on the existing styles of some members.

Re: AI is forcing us to write good code

#87

Earlier quoted context omitted.

that's interesting, whats the reason for that?

Hi, the reason I have this expectation is that on a (cognitively) diverse team there will be a range of reactions that all need to be accommodated. some (many?) devs don't want agents. Either because the agent takes away the 'fun' part of their work, or because they don't trust the agent, or because they truly do not find a use for it in their process. I remember being on teams which only remained functional because…

thanks for the reply, thats interesting

i was thinking it was more like llms when used personally can make huge refactorings and code changes that you review yourself and just check it in, but with a team its harder to make sweeping changes that an llm might make more possible cause now everyone's changes start to conflict... but i guess thats not much of an issue in practice?

Re: AI is forcing us to write good code

#88
post #77

I can't reconcile how the CEO of an AI startup is; on one hand pushing "100% Percent [sic] Code Coverage" while also selling the idea of "Less than 60 seconds to production" on their product (which is linked in the first screen-full of the blog post so it's not like these are personal thoughts). If 100% code coverage is a good thing, you can't tell me anyone (including parallel AI bots) is going to do this correctly…

The US seems to be beta testing the idea that the most successful CEOs are the ones that can convince investors to buy the most shares at the highest prices based on the biggest lies.

Re: AI is forcing us to write good code

#89

Earlier quoted context omitted.

Hi, the reason I have this expectation is that on a (cognitively) diverse team there will be a range of reactions that all need to be accommodated. some (many?) devs don't want agents. Either because the agent takes away the 'fun' part of their work, or because they don't trust the agent, or because they truly do not find a use for it in their process. I remember being on teams which only remained functional because…

thanks for the reply, thats interesting i was thinking it was more like llms when used personally can make huge refactorings and code changes that you review yourself and just check it in, but with a team its harder to make sweeping changes that an llm might make more possible cause now everyone's changes start to conflict... but i guess thats not much of an issue in practice?

oh yeah well that's an extreme example of how one dev's use could overwhelm a team's capacity.

Re: AI is forcing us to write good code

#90
post #77

I can't reconcile how the CEO of an AI startup is; on one hand pushing "100% Percent [sic] Code Coverage" while also selling the idea of "Less than 60 seconds to production" on their product (which is linked in the first screen-full of the blog post so it's not like these are personal thoughts). If 100% code coverage is a good thing, you can't tell me anyone (including parallel AI bots) is going to do this correctly…

Cargo Cult Steve Jobs is your answer.
Post reply on HN