cm0002 ( cm0002@lemmy.zip ) to Programmer Humor@programming.dev · 11 months agoMore code = more betterlemmy.zipimagemessage-square23linkfedilinkarrow-up1385
arrow-up1385imageMore code = more betterlemmy.zipcm0002 ( cm0002@lemmy.zip ) to Programmer Humor@programming.dev · 11 months agomessage-square23linkfedilink
minus-squareHirom ( Hirom@beehaw.org ) linkfedilinkarrow-up29·11 months agoThe compiler will optimize it anyway. /s
minus-squareDumhuvud ( Dumhuvud@programming.dev ) linkfedilinkEnglisharrow-up18·11 months agoYou jest, but you aren’t wrong. At least if we are talking about C, C++ or Rust. https://godbolt.org/z/oPPfdfcf5 .NET compiler is weak when it comes to optimizing your code; I assume Go’s is as bad.
minus-squareyetAnotherUser ( yetAnotherUser@discuss.tchncs.de ) linkfedilinkarrow-up5·11 months agoNot sure about the last one though. The other two are trivial to optimize away.
minus-squareHirom ( Hirom@beehaw.org ) linkfedilinkarrow-up3·11 months agoAn infinite loop canot be ruled out in the last case, so a compiler couldn’t optimize this away without potentially changing the program behavior.
minus-squareyetAnotherUser ( yetAnotherUser@discuss.tchncs.de ) linkfedilinkarrow-up1·11 months agoInfinite loops are often weird though. They could be seen as undefined behavior and the compiler may do whatever it feels like.
The compiler will optimize it anyway. /s
You jest, but you aren’t wrong. At least if we are talking about C, C++ or Rust. https://godbolt.org/z/oPPfdfcf5
.NET compiler is weak when it comes to optimizing your code; I assume Go’s is as bad.
Not sure about the last one though. The other two are trivial to optimize away.
An infinite loop canot be ruled out in the last case, so a compiler couldn’t optimize this away without potentially changing the program behavior.
Infinite loops are often weird though. They could be seen as undefined behavior and the compiler may do whatever it feels like.