Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi,
i have one web application when i build it i found lot of warning which says that lot of variables are declared but never used. some of them are exception objects in catch blocks etc..others are declared previously but now the requirement changes. there are many other warning like type casting etc... now i would like to know does this kind of code affect the performance of the project. if yes how ?

i know this is kind of bad programming but this is existing project and there are a lot of pages where i have this problem so not want to go to every page and remove that code and etc...
Posted
Updated 30-Jan-14 19:20pm
v2
Comments
Rahul VB 31-Jan-14 13:33pm    
Good question

Quote:
Compiler warnings can provide some additional insight and quality controls on your codebase. They can tell you about obsolete code, unused variables, and many other items that you wouldn’t necessarily see on visual inspection. Warnings can also surface bugs, such as possible null reference exceptions, or expressions that always evaluate to “true”.


Quote[^]

Warnings do effect the performance of the Project in a larger way. Warnings such as declaring a variable and never using it means the memory consumption shoots up since the memory is allocated for unwanted/unused variables.

Same is the case with the efficient use of Exception Handling in the code.

And , the best thing to avoid these is to treat compiler warnings as Error.

Refer
Treat Warning as Error[^]
 
Share this answer
 
Comments
Rahul VB 31-Jan-14 13:34pm    
Nice....
Unused variables will not have any effect on your code stability or performance. It's just a bad programming practice to declare variables and not use them.

On the contrary, unused Exception variables in the catch block means you're not logging the exceptions. It could even be an empty catch block which means that if an exception is thrown at runtime, you app swallows the exception but does nothing about it. It might lead to an unstable data state in your app.

Each warning has a different meaning that must be investigated and fixed.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900