▲ 273 ▼ More code = more better (lemmy.world) submitted 11 months ago by hoch@lemmy.world to c/programmerhumor@lemmy.ml 25 comments fedilink hide all child comments
[–] ryannathans@aussie.zone 17 points 11 months ago (6 children) I'd be shocked if 4 got optimised out permalink fedilink source parent hideshow 6 child comments replies: [–] Mio@feddit.nu 11 points 11 months ago (1 child) It is used to warm up the house. permalink fedilink source parent hideshow 1 child comment replies: [–] MangoCats@feddit.it 4 points 11 months ago 4 is used for non-deterministic delay - - - is Random.nextInt() also cryptographically secure? permalink fedilink source parent [–] ferric_carcinization@lemmy.ml 2 points 11 months ago (3 children) I feel like an idiot. Also, in the "Good" example, no underflow occurs. i goes from 0 to -10, and x is assigned to -i every loop. It might still be possible to optimize away the random number example, if the random function were made a magic language item, but it would not be even remotely close to being worth the effort. permalink fedilink source parent hideshow 3 child comments replies: [–] MangoCats@feddit.it 2 points 11 months ago (2 children) The question the optimizer can't really answer is: will Random.nextInt() ever return 10? If that's a 64 bit integer it could be a LOOOOOONG time before 10 ever shows up. permalink fedilink source parent hideshow 2 child comments replies: [–] ferric_carcinization@lemmy.ml 1 point 11 months ago If it were a magic lang item, you could treat the resulting value in a special way. Then, you could create an optimization pass for this situation: if a variable is assigned random in a loop and the loop can only be exited with a certain value, the compiler can coerce the magic rand value to it. permalink fedilink source parent [–] ryannathans@aussie.zone 1 point 11 months ago Ah yes the halting problem permalink fedilink source parent
[–] Mio@feddit.nu 11 points 11 months ago (1 child) It is used to warm up the house. permalink fedilink source parent hideshow 1 child comment replies: [–] MangoCats@feddit.it 4 points 11 months ago 4 is used for non-deterministic delay - - - is Random.nextInt() also cryptographically secure? permalink fedilink source parent
[–] MangoCats@feddit.it 4 points 11 months ago 4 is used for non-deterministic delay - - - is Random.nextInt() also cryptographically secure? permalink fedilink source parent
[–] ferric_carcinization@lemmy.ml 2 points 11 months ago (3 children) I feel like an idiot. Also, in the "Good" example, no underflow occurs. i goes from 0 to -10, and x is assigned to -i every loop. It might still be possible to optimize away the random number example, if the random function were made a magic language item, but it would not be even remotely close to being worth the effort. permalink fedilink source parent hideshow 3 child comments replies: [–] MangoCats@feddit.it 2 points 11 months ago (2 children) The question the optimizer can't really answer is: will Random.nextInt() ever return 10? If that's a 64 bit integer it could be a LOOOOOONG time before 10 ever shows up. permalink fedilink source parent hideshow 2 child comments replies: [–] ferric_carcinization@lemmy.ml 1 point 11 months ago If it were a magic lang item, you could treat the resulting value in a special way. Then, you could create an optimization pass for this situation: if a variable is assigned random in a loop and the loop can only be exited with a certain value, the compiler can coerce the magic rand value to it. permalink fedilink source parent [–] ryannathans@aussie.zone 1 point 11 months ago Ah yes the halting problem permalink fedilink source parent
[–] MangoCats@feddit.it 2 points 11 months ago (2 children) The question the optimizer can't really answer is: will Random.nextInt() ever return 10? If that's a 64 bit integer it could be a LOOOOOONG time before 10 ever shows up. permalink fedilink source parent hideshow 2 child comments replies: [–] ferric_carcinization@lemmy.ml 1 point 11 months ago If it were a magic lang item, you could treat the resulting value in a special way. Then, you could create an optimization pass for this situation: if a variable is assigned random in a loop and the loop can only be exited with a certain value, the compiler can coerce the magic rand value to it. permalink fedilink source parent [–] ryannathans@aussie.zone 1 point 11 months ago Ah yes the halting problem permalink fedilink source parent
[–] ferric_carcinization@lemmy.ml 1 point 11 months ago If it were a magic lang item, you could treat the resulting value in a special way. Then, you could create an optimization pass for this situation: if a variable is assigned random in a loop and the loop can only be exited with a certain value, the compiler can coerce the magic rand value to it. permalink fedilink source parent
[–] ryannathans@aussie.zone 1 point 11 months ago Ah yes the halting problem permalink fedilink source parent