Out of Order Execution #2663
-
Hi All, I just had a thought that I wanted to share. I know that with myself, I often write code in a logical order and not necessarily the order that I need the data. For example, I might write the following code:
But really the following code would be better:
because it would defer the execution of Attorneys until after Staff is executed (and potentially GCed). I would like to propose that the C# compiler be allowed to rearrange independent, side-effect free statements so that execution is deferred whenever possible. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
The C# compiler is already allowed to do anything that has no observable effects other than its effect on performance. That would include rearranging independent, side-effect free statements so that execution is deferred whenever possible. Unfortunately proving that statements are independent and side-effect free is almost impossible in C#, for all but the most trivial of cases. |
Beta Was this translation helpful? Give feedback.
The C# compiler is already allowed to do anything that has no observable effects other than its effect on performance. That would include rearranging independent, side-effect free statements so that execution is deferred whenever possible.
Unfortunately proving that statements are independent and side-effect free is almost impossible in C#, for all but the most trivial of cases.