views:

66

answers:

4

Okay so my situation at work is that I've written about 200 or so lines of additional functionality into an aspx page's code-behind that is currently not to be implemented. It is in a subroutine that handles an event that currently has zero chance of occurring.

Because this code is not being used, I've gotten curious. Should I comment out the subroutine that has zero chance of firing? Would it do anything to enhance the performance of the page or anything like that if I did indeed comment it out? Or could/should I just leave it as is? Thanks in advance.

+1  A: 

I have no reason to believe it will make any difference whatsoever.

The only time I think it would matter is if you had loads of commented out stuff in HTML or something that actually had to be processed or rendered.

Why don't you try logging the execution times of a routine that calls methods in the same file as the code both commented out and not commented out to test it?

Evernoob
I do have some ASP tags in the front-end that I've set Enabled="false" and Visible="false" (they're the ones that would cause this event to fire) so that they do not render. BUT it's still there, so I'd imagine the compiler has to at least do SOMETHING with it..
KSwift87
+1  A: 

if there is nothing that actually causes the code to be called, there is no need to comment it out.

Sure, it will be added into the compiled assembly, but it isn't going to cause any performance boost on the part of your web application.

Mitchel Sellers
+11  A: 

A few comments:

  1. Performance is often quite unintuitive, there's no substitute for careful measurement.
  2. Any compiled code in your address space consumes resources. So there might be some overhead. But how much realtive to everything else happening? My guess is very little or even negligable but see item 1.
  3. Unexpected things happen as applications scale, negligable things can become important when they are copied mutliple times. So prefer to keep things tidy.
  4. If you are using a source code management system then simply delete the code, it's saved in the old versions in the repository. Keep your code tidy. Commented-out code scares the maintainer.
djna
+1 for comment 4.
Daniel Dyson
I'm not a big fan of commenting out huge blocks of code either, and I like the point you made in #4. Problem is I haven't checked this project in at all yet because my project manager hasn't made a ticket for it yet.. Anywho it was my supervisor who told me to leave the code in there, but comment it out in case the Field Operations department would like the additional functionality. Since this event code stands 0 chance of firing, I haven't commented it out. Not commenting it out however got me curious, and hence this question. :-) Thank you for the response.
KSwift87
+1  A: 

Its highly unlikely that you will measure any significant differences if you throw in a couple of unused methods. They probably will be weeded out as part of compiler optimizations and may not even have any object code generated.

But useless code commented or otherwise surely scares a lot (#4 djna above)

d-live