r/java • • 5d ago

Telltale signs of Vibecoding in Java?

Someone recently flagged one of my mods as being "obviously vibecoded" (which it wasn't), so I appealed the decision. just out of curiosity, what exactly are the signs people are seeing when accusing code of being vibecoded?

98 Upvotes

161 comments sorted by

View all comments

30

u/voronaam 5d ago

Another sign is unit tests that "hug" the code really close.

I once had a one-liner that changes default value of some flag in the application from true to false - the PM changed their mind. The original code and tests were written by AI. Do you want to guess how many unit tests failed after this tiny change? I expected exactly one. Maximum two. I expected there to be a test for the default behavior that I'd need to update and a random unrelated test that relied on the default.

Failed tests: 6. All directly related to the default.

AI wrote the tests and assertions for:

  • When the value is missing, it is treated as true
  • When the value is false it is false
  • When the value is true it is true
  • When the value was missing and gets set to true it is true and no longer missing
  • When the value was missing and gets set to false it is false and no longer missing
  • When the value was set to false and is deleted it is true

No sane human would ever write that many tests for a trivial boolean flag. It was left configurable to begin with because the PM was not sure which way they want it It is not like we expected PM to be changing it back and forth all the time.

When changing 1 line of code leads to 40+ lines of unit test changes - the tests are "hugging" the code way too close.

AI loves doing that for some reason. I guess it was getting scored by the lines of code it produced...

7

u/Tiziano75775 5d ago

I usually ask to reach 80-90% coverage with as few tests as possible, it avoids to make too many tests for the same line

4

u/Zatujit 4d ago

isn't it the point of unit tests?

2

u/voronaam 4d ago

Not really. The point of unit tests is to cover the desired functionality, not to re-express the current implementation in assertions.

For example, if you have a "UserService", a good test might call a createUser method and then assert that getUserCount() == 1 and findUser(...) returns the creted users.

An AI-written test is quite likely to additionally reach straight into the DB with a couple of SELECT to assert the record is created in exactly the format it is done now, assert that a log line written as plaintext to a log file, assert that a metric usersCreated is emitted in Prometheus format, and also have a "no other interactions" assertion in the end.

Witch such a test and for no good reason it would be harder to switch from PostgreSQL to MongoDB, switch the loggers to structured format, add support for CloudWatch metrics or to literally add any functionality like queued up marketing events tied to user registration.

A human written tests cover the functionality that matters. If after creating a new user the total count of users is wrong - it is a bug. It is helpful to have a test that'd fail on it. The AI loves to write tests the cover everything else.

Another example is when the code has a bug. I've seen AI to find it - and happily cover it with a test. For example, human writing a test and finding out that "user names with a hyphen cause exception" would fix the exception. AI would write a test "hyphenated names are not allowed" - hugging the existing implementation insanely close, down to the exact bugs in it.

1

u/Yesterdave_ 5d ago

And have you found a strategy to get the AI to not do that?

2

u/voronaam 5d ago

Me personally? When I do story work, I just tell it to not write any tests until directed. And then I tell it which tests to write. When I do bugs, I like to do TDD. So there a single test written to reproduce the bug to begin with. No more tests added later on.

Note that it is not an "agentic" approach. I have seen so many people try and fail to get a bunch of Markdown files to make LLM behave differently. It never works.

1

u/laplongejr 3d ago

No sane human would ever write that many tests for a trivial boolean flag.

I would... along the date of the exact massive impact when the trivial change broke prod in 5 different ways.

1

u/voronaam 2d ago edited 2d ago

The fun part is that covering the codebase with trivial tests is not going to prevent things going wrong in production. But it will make the whole CI/CD pipeline a lot slower - increasing the time it takes to rollout the fix for whatever breaks production.

A developer can write a cross join SQL query (O(n*m)) and cover it will all the tests imaginable - it will blow up in production when a user makes it run against a reasonably sized dataset. If the API server is going down every time a user visits the /reports/ page and it takes 8 hours to get the hotfix the CI/CD pipeline - nobody is going to be happy.

Good unit tests are a blessing. The biggest value they provide is letting the developers refactor the troubled areas in the application with a reasonable certainty that the application's logic is still intact.

Writing a good test suite is a bit of an art - with very few practitioners even among the humans. Most developers do not like writing the tests. Most QA people are either not allowed, not capable or not paid enough to do it. Most managers just want the "line/branch coverage" report to be green against some arbitrary percentage number. With very few codebases out there having a good test suite, very few books written on the subject - what are the chances AI has in its training set anything to teach it about a good test suite?

I can share another anecdote. We recently let AI loose in one of the projects and nobody paid much attention to the tests it was writing. The AI found a flag that was set on just 3 unit tests that were starting a whole application in Docker and testing some APIs (more of an integration test written in a unit test format) - and decided to apply that flag to all the unit tests. Even a small utility method that is basically a packaged regex was tested against a fully launched application. It did not make tests any better, but it made them A LOT slower and the pipelines started to fail with out-of-memory errors. A Java application is usually memory hungry and starting literally hundreds of them in parallel just to test a single bean inside may not be the best idea ;)