views:

755

answers:

3

In Visual Studio 2008 there is an option "Optimize Code" that probably corresponds to the /optimize option. It is never enabled, not even when in "Release" mode.

Why should I not want this option to be enabled at all times?

+7  A: 

It is on per default for release builds (perhaps you changed the settings for Release builds?). Turn it off to make debugging easier. For release code, turn it on.

Brian Rasmussen
Hmm, must have unknowingly turned it off then. Will tick it again :p
borisCallens
+4  A: 

Code optimisation has gotten pretty good in C#3 - it does lots of clever performance tweaks that change your code quite a lot more in the IL than you might expect.

Some obfuscation tools (and some other IL tools like ILMerge) can sometimes break the assembly with optimisation on. The more IL tools you use the more likely you are to get serious issues with optimisation.

Also as @Brian Rasmussen already said (+1) - you want it off for debugging, on for releases.

Keith
+1  A: 

To make this clear, optimization does inline functions and eliminate some variables. When debugging optimized code, you won't get as much help by the IDE as usual, since some of the code actually does not exist anymore. So for debugging, turn if off (default).

In languages like C++ optimization sometimes (often) has critical side effect that need to be considered. As far as i know, this is not or almost not the case for C#, so from the point of correctness of your code, it probably does not matter if you optimize or not.

mafutrct