this post was submitted on 13 Dec 2025
283 points (98.0% liked)

Programmer Humor

42111 readers
1 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
[–] ferric_carcinization@lemmy.ml 18 points 5 months ago* (last edited 4 months ago) (11 children)

The compiler should be able to optimize all of them to the same machine code.

  1. This is already good.
  2. Easily optimized by constant folding.
  3. ~~This one depends on the semantics of signed underflow, so it may not do what you want.~~
  4. ~~The loop can only exit if x==10, so as long as the nextInt() method doesn't have side effects, the loop should be eliminated. But, again, language semantics can affect this.~~

Edit: Very wrong for 3 & 4, see replies.

[–] ryannathans@aussie.zone 18 points 4 months ago (6 children)

I'd be shocked if 4 got optimised out

[–] Mio@feddit.nu 11 points 4 months ago (1 children)
  1. It is used to warm up the house.
[–] MangoCats@feddit.it 4 points 4 months ago

4 is used for non-deterministic delay - - - is Random.nextInt() also cryptographically secure?

load more comments (4 replies)
load more comments (8 replies)