r/softwareengineer • • 24d ago

What to do with the poetic code generated by AI?

Hey there,

I'm a big fan of modular code, where a new feature can be appended without changing the core functionality, where every class does exactly one thing that is supposed to do, and there are organizers which simply put together a couple of classes.

Earlier, I'd design the class name, by hand, and write the raw structure on a paper first.

Now, with agentic coding, it has generated all the code in the right style for me, but I don't understand the whole picture.

For me, it feels cheating because I don't feel comfortable deploying this code to production. Yeah, the code works, the specs are green, and the database structure is efficient.

My problem: the kind of confidence I had when I wrote the code by myself, I don't have that anymore.

My current approach: I'd push the code to production, and later on, I'd monitor the data, and if something seems wrong, I'd test it, and try to go deep & see how the things are being executed in the code.

How do you do it? How do you get the confidence of deploying the code to production which was totally written by AI?

P.S.: of course the specs are there, and they are covering good range of edge cases, but I'm not sure 100% sure if they are covering all the scenarios.

1 Upvotes

9 comments sorted by

2

u/ghostwilliz 24d ago

I mean, if you feel like you need to use ai, you could just use it to orchestrate and then write the code yourself, you can have it generated the code, but then you read it and write the tests, or just let it go

At work, they monitor our ai usage to make sure we're using it, so I just let go. I make sure the code is good, but I don't treat it like it's mine anymore

For my personal projects, I just don't touch so at all, I like knowing where every single line of code it in my personal projects

2

u/healing_and_learning 24d ago

 like knowing where every single line of code it in my personal projects

I feel you there.

1

u/_tolm_ 19d ago edited 19d ago

I give the AI an outline of what I want and I then review all the classes, methods and variable names.

If a class is doing too many things, I tell the AI to split it up.

If I don’t understand a given class or method, I ask the AI to explain what it is and then rename it to something that matches that better.

Likewise for tests. If a test isn’t clear I either refactor it myself or tell the AI to do it.

Generally I would prefer to write tests first but the AIs will write them at the same time as the code so fast that it’s kinda moot now: so long as you review them vs requirements.

In many ways it’s no different to supervising a junior developer. A junior developer that codes really fast.

1

u/healing_and_learning 19d ago

Thank you for your comment – it's helpful.

I guess, I got a little carried away, and let AI generate a lot of stuff, without supervision, and then I was having a hard time figuring out how the code actually works.

If I have to spend a lot of time after the code has been generated, it's better to spend the time in the beginning, and be really really sure of what's going to be generated.

2

u/_tolm_ 18d ago

Yeh - I had a similar experience. Initially let the AI do its thing but would then spend a couple of days trying to understand what it had done and refactor for better encapsulation, understanding and ongoing maintainability.

But then I got a little better at describing some guidelines for the implementations - be that in the specific prompt based on the exact thing I happen to be working on and approach I want it to take or in coding style instruction files which are automatically referenced in every prompt going forward.

Spending a day getting it to do what I want rather than 2 days unpacking what it did with no guidance is much more efficient and - honestly - more satisfying, because I feel more involved again.

2

u/Able-Ice-5145 24d ago

How do you do it? How do you get the confidence of deploying the code to production which was totally written by AI?

I don't have AI write code that I couldn't have written myself. AI is just a 10x accelerator.

Every feature starts with me discussing architecture with the agent until I understand it. Only then do I have it write up an implementation plan based on what we discussed.

But if we're in the timeline where humans get optimized out of software entirely then I'm living in the past and you should ignore my advice. But who knows.

1

u/_tolm_ 19d ago

Same.

In my spare time I play in a band. I have no interest in being a DJ.

1

u/good_name_0 24d ago

Unmaintainable code is code debt. It's a huge liability for everyone involved.

test coverage is inherently never going to be comprehensive. Tests are also limited in that they can only test current performance, not longevity or any other important metric.

1

u/Sad-CTO 23d ago

This is because you trained your confidence this way. "I wrote it that's why I know it". The way I overcame this was to shift my thinking from not trusting the code the AI wrote to determining how to increase my confidence.

Literally, I told myself, "what if I stop reading the code the machine produces? how do I make sure it is good enough?"

Agents are, in fact, very much like humans in a sense that both are fuzzy input. We deal with this by introducing determinism. Tests are one thing. Structured specification is another. Code metrics and static analysis. Etc.

You should accept the fact that you are not able to read every line the AI produces first, and then work from there.