in reply to Re^8: Without trying; what do you think this would print? (notabug!)
in thread Without trying; what do you think this would print?

I get what you're saying, but I still disagree. It may be an optimization quirk, but it's also still a bug.

The extended assignment operators are there to provide a syntax shortcut, and yes, to provide the compiler with additional information it can use to optimize the implementation. However, you can't redefine changes in behavior as simple "wiggle room". There is no, this will equal either 0 or 1. This is programming, it needs to have defined behavior.

$ perl -e '$a{0} = scalar keys %a; print $a{0}' 0 $ perl -e '$a{0} = $a{0} || scalar keys %a; print $a{0}' 0 $ perl -e '$a{0} ||= scalar keys %a; print $a{0}' 1 $ perl -e '$a{0} = $t ||= scalar keys %a; print $a{0}' 0

Yes, it's an edge case. Yes, it's an edge case that is an acceptable variance in behavior for me at least. But that variance in behavior is still a bug (in my opinion ...).

  • Comment on Re^9: Without trying; what do you think this would print? (notabug!)
  • Download Code