this post was submitted on 13 Dec 2025
280 points (97.9% liked)

Programmer Humor

39911 readers
34 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 6 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
[โ€“] MimicJar@lemmy.world 6 points 4 weeks ago (1 children)

For #4 if the Random instance weren't "new", then calling the nextInt() function would definitely have side effects, since the next integer would pull one away from the random stack.

However unlike the first three which will run within a consistent amount of time, #4 will take an unknown amount of time to run, so you can't just collapse it and eliminate the loop.

For example a very simple race game where a participant moves a random number of steps each turn, we may want to time how long that race takes. We can't just say that they will reach the end immediately. In fact technically we don't know that they will ever finish the race... But that's the halting problem and a whole other issue.

I don't know what I was thinking.

But, if you borrow C's semantics, you are allowed to "optimize" away side-effect-less loops, even if they would never terminate. But that would require the random method to be pure.