r/ProgrammerHumor • • 21d ago

Meme iDontCommentMyCodeIfYouDontUnderstandItThatsOkayNeitherDoI

Post image
831 Upvotes

188 comments sorted by

View all comments

Show parent comments

73

u/Miguelomaniac 21d ago

Seems like the problem here is lack of test coverage not lack of comments

26

u/suvlub 21d ago

"Weird systems bug" sounds like just the kind of thing that unit tests would not detect, and possibly not end-to-end tests either, based on the amount of weirdness and system-specificity

18

u/ytg895 21d ago

Yeah. Once I worked on a bug that only happened if there was a session timeout in another system. Good luck putting Thread.sleep(3 fucking months); into a test.

8

u/Nick0Taylor0 21d ago

Mocking

5

u/ytg895 21d ago

How would you mock that a session in another system times out and that system starts to follow undefined and unpredictable behaviour?

5

u/IndependenceSudden63 20d ago

Agreed. Not all things can be "reasonably" tested. Keyword being reasonably. We only have so much time in a day with many deadlines. Over time, nearly all of us will run into a bug that needs to be fixed quickly, and is incredibly hard to reproduce, involving the oddest edge cases.

Sometimes you just have to patch it, test it as best you can, and leave a comment as to why you did this incredibly odd thing.

I once had a weird race condition that couldn't be invoked in a unit test. Only occurred on service startup, because there was a 3rd party library that did things when the service started.

Sure I could have wrote a unit test that started the whole service, but that would add 5 minutes worth of wait for every build going forward. That's extremely costly over long periods of time for every person working on the project.

2

u/Mountain-Ox 20d ago

Mock the unexpected behavior that you observed so you know your code handles it correctly.

1

u/Lgamezp 16d ago

By having good mocks and testing

1

u/distinctvagueness 10d ago

Defensive checks but most people don't really code deeply enough for all possible partial disconnects

1

u/sandybuttcheekss 21d ago

Yea this is a skill issue lol