3

Is there any tool or way I can check how can I optimize my code? removing redundancy? I am using VS 2010

Thanx

BreakHead
  • 10,480
  • 36
  • 112
  • 165

8 Answers8

4

I don't know about removing redundancy, but ReSharper has some nice code analysis features that can help to identify unused code blocks. It can also make suggestions for cleaner code, but it's not always 100% accurate.

jamshehan
  • 1,481
  • 1
  • 10
  • 9
3

Such tools, even if they existed, wouldn't be reliable. The best would be to perform a code review by a good developer or architect.

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
1

No tool can replace experience and expertise. There are a number of productivity tools that can help, a popular one being ReSharper for example, but it's not going to fix everything for you. At some point you just have to rely on your abilities and the abilities of your team members. Learning how to code well takes time.

It often helps to step back and look at your code with the mindset of certain design principles. S.O.L.I.D. can be a great place to start. Some other questions you can ask yourself are:

  • Are your classes and types properly encapsulated?
  • Is your code test-driven or behavior-driven in any way?
  • Do your tests define discrete unit of behavior, or are they just tailored to the implementation that's being tested?
  • To specifically address redundancy, quite simply, do you have copied/pasted code doing the same thing in two places?
David
  • 208,112
  • 36
  • 198
  • 279
0

A profiler will give you a good idea of where your application spends most of its time. From knowing what to how to optimize, though, requires experience as well as knowledge of both the code base in general and the problem domain.

user
  • 6,897
  • 8
  • 43
  • 79
0

What you want is Code Coverage tools. These keep a record of which lines of code are executing. In order for this to be effective, a complete test suite, or manual test run, is required. This will show up the lines of code that are never used, and will help you make decisions.

Static analysis can also help you with code paths and give you information about how and where your code is called.

A couple of good question sabout code coverage:

What can I use for good quality Code Coverage for C#/.NET?

C# Code Coverage metrics

Also look at Microsoft's FxCop for static analysis:

http://msdn.microsoft.com/en-us/library/bb429476(VS.80).aspx

Community
  • 1
  • 1
Joe
  • 46,419
  • 33
  • 155
  • 245
0

There is http://clonedetectivevs.codeplex.com/ which is a VS plugin. It uses http://conqat.cs.tum.edu/ under the hood. I've not really used it but does what you asked. Couple that with code reviews and might help.

nportelli
  • 3,934
  • 7
  • 37
  • 52
0

There is a (commercial, 249€) solution checking for duplicate code, even in large projects.

http://www.solidsourceit.com/products/SolidSDD-code-duplication-cloning-analysis.html

Bionicman303
  • 1,293
  • 3
  • 12
  • 15
0

For that purpose we use the build-in Duplicated Finder in our TeamCity build server.

Simon Fischer
  • 3,816
  • 3
  • 23
  • 32