During my trial of ReSharper 5, I noticed its version of IntelliSense falls behind Visual Studio 2010's in three ways that were key to me:
ReSharper doesn't support IntelliSense in the "QuickWatch..." debugger utility.
ReSharper's IntelliSense seems to break down for me in .aspx files between the <%= %> tags.
I couldn't find a way to get a listing of properties within an object initializer block. (VS does this if you hit the space key.)
Thankfully ReSharper lets you use Visual Studio IntelliSense alongside its other great features. Am I missing out on anything great by not using ReSharper's IntelliSense?
Well you're losing quite a bit. Here are some quick facts about ReSharper code completion: http://www.jetbrains.com/resharper/webhelp/Coding_Assistance__Code_Completion.html
Smart Completion (Ctrl+Shift+Space in IntelliJ IDEA keymap) is especially useful because in common scenarios it gives you a narrow selection of symbols that you most likely want to complete, and in some cases acts as a shortcut to code generation features
By the way, Smart Completion is the kind of completion that you should use with object initializers: www.jetbrains.com/resharper/webhelp/Coding_Assistance__Code_Completion__Smart.html#object_initializers
As for completion within the <%= %> pair, this should work fine. Please let us know what exactly went wrong by submitting an issue to youtrack.jetbrains.net/issues/RSRP Thanks!
P.S. I work at JetBrains
A five minute comparison I'd say that ReSharper's gives you a bit of help in the typing.
So if you have a method that's A(int a, int b) and you hit ctrl+space when you select A it will add (), will place you in the middle of the brackets and will show you the information about the method. Other than that you're probably not missing much.
For me that is quite helpful, but if you're having trouble doing ASP.NET and those are known bugs / limitations its always best to pick the best tool for the job.
Personally I turn it off. It is annoying and slows me down. Here is a prime example:
No you're not missing much apart from a test runner that supports NUnit. I've had the same problem and also (rather worryingly), hideous performance. I tend to use the productivity power tools extension and the native refactor stuff instead. Info here:
http://visualstudiogallery.msdn.microsoft.com/en-us/d0d33361-18e2-46c0-8ff2-4adea1e34fef
R# also does stuff which I plainly do not want to do and my code ends up littered with commented resharper hints.
I find the CompleteCodeSmart functionality something I use frequently and save me alot of typing.
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
I have to refactor a large C# application, and I found a lot of functions that are never used. How can I check for unused code, so I can remove all the unused functions?
Yes, ReSharper does this. Right click on your solution and selection "Find Code Issues". One of the results is "Unused Symbols". This will show you classes, methods, etc., that aren't used.
It's a great question, but be warned that you're treading in dangerous waters here. When you're deleting code you will have to make sure you're compiling and testing often.
One great tool come to mind:
NDepend - this tool is just amazing. It takes a little while to grok, and after the first 10 minutes I think most developers just say "Screw it!" and delete the app. Once you get a good feel for NDepend, it gives you amazing insight to how your apps are coupled. Check it out: http://www.ndepend.com/. Most importantly, this tool will allow you to view methods which do not have any direct callers. It will also show you the inverse, a complete call tree for any method in the assembly (or even between assemblies).
Whatever tool you choose, it's not a task to take lightly. Especially if you're dealing with public methods on library type assemblies, as you may never know when an app is referencing them.
Resharper is good for this like others have stated. Be careful though, these tools don't find you code that is used by reflection, e.g. cannot know if some code is NOT used by reflection.
As pointed Jeff the tool NDepend can help to find unused methods, fields and types.
To elaborate a bit, NDepend proposes to write Code Rule over LINQ Query (CQLinq). Around 200 default code rules are proposed, 3 of them being dedicated to unused/dead code detection
Basically such a rule to detect unused method for example looks like:
// <Name>Dead Methods</Name>
warnif count > 0
from m in Application.Methods where !m.MethodsCallingMe.Any()
select m
But this rule is naive and will return trivial false positives. There are many situations where a method is never called yet it is not unused (entry point, class constructor, finaliser...) this is why the 3 default rules are more elaborated:
Potentially dead Types (hence detect unused class, struct, interface, delegate...)
Potentially dead Methods
Potentially dead Fields
NDepend integrates in Visual Studio 2022, 2019, 2017,2015, 2013, 2012, 2010, thus these rules can be checked/browsed/edited right inside the IDE. The tool can also be integrated into your CI process and it can build reports that will show rules violated and culprit code elements. NDepend has also a VS Team Services extension.
If you click these 3 links above toward the source code of these rules, you'll see that the ones concerning types and methods are a bit complex. This is because they detect not only unused types and methods, but also types and methods used only by unused dead types and methods (recursive).
This is static analysis, hence the prefix Potentially in the rule names. If a code element is used only through reflection, these rules might consider it as unused which is not the case.
In addition to using these 3 rules, I'd advise measuring code coverage by tests and striving for having full coverage. Often, you'll see that code that cannot be covered by tests, is actually unused/dead code that can be safely discarded. This is especially useful in complex algorithms where it is not clear if a branch of code is reachable or not.
Disclaimer: I work for NDepend.
I would also mention that using IOC aka Unity may make these assessments misleading. I may have erred but several very important classes that are instantiated via Unity appear to have no instantiation as far as ReSharper can tell. If I followed the ReSharper recommendations I would get hosed!
ReSharper does a great job of finding unused code.
In the VS IDE, you can right click on the definition and choose 'Find All
References', although this only works at the solution level.
The truth is that the tool can never give you a 100% certain answer, but coverage tool can give you a pretty good run for the money.
If you count with comprehensive unit test suite, than you can use test coverage tool to see exactly what lines of code were not executed during the test run. You will still need to analyze the code manually: either eliminate what you consider dead code or write test to improve test coverage.
One such tool is NCover, with open source precursor on Sourceforge. Another alternative is PartCover.
Check out this answer on stackoverflow.
I have come across AXTools CODESMART..Try that once.
Use code analyzer in reviews section.It will list dead local and global functions along with
other issues.
FXCop is a code analyzer... It does much more than find unused code. I used FXCop for a while, and was so lost in its recommendations that I uninstalled it.
I think NDepend looks like a more likely candidate.
There is an old video of Notch debugging and testing his code and while doing so he simply pauses his game, makes his code modifications, and resume his game with the new changes.
I found this old post explaining how he does it, but I'm wondering if there is an equivalent to Visual Studio 2012.
I know that you can enable Edit and Continue but this is a lot more restricted in the sense that you can't edit anything you want and you need to set a breakpoint. So Edit and Continue is not quite what I'm looking for.
I know that you can enable Edit and Continue but this is a lot more restricted in the sense that you can't edit anything you want …
Yes, there are some things that you can't edit with Edit and Continue. But that's the best you can do with the current tools, I don't think there is a way around that.
… and you need to set a breakpoint
No, you don't. You can use the “pause” button in VS (real name Break All), edit your code and then let it continue executing.
.NET's edit and continue is nowhere near as good as that provided by Visual C++, Visual Basic or any dynamic (ie script) languages which is a pity.
If you can live with the limitations (having to break execution, no 64-bit support unless you are v4.5.1+, no lambda/linq changes, changing active statements, and a few others) then you should be ok to do pretty much the same. I find though, that I always end up wanting to change something that's unsupported :(
The big alternative is to use unit tests - in that, if you have enough tests you do not need to go debugging into your code at all. I think its debatable whether you save more time or not, and maybe it depends on the programmer style which suits you better.
I am using camelCase convention for private member variables in my C# projects. Because of changed code quality requirements now I "have to"/"would like to" rename/refactor all these members to _camelCase.
For example logger will be _logger.
Additional info:
1) I definitely know that a particular rename/refactor could cause error, and an interactive refactor tool will warm me in that case. Still I want to automate mass rename, I'll take the risk ending with not compilable source what needs manual corrections.
2) I use latest ReSharper if this helps, but still I can not figure solution for my task. (To be clear I do not suggest ReSharper should be the solution, just a possibility.
Thanks in advance
There is a guy called Steve Cadwallader who has made a visual studio extension called "CodeMaid" (http://www.codemaid.net/). It has several things you can use for cleaning up code etc and the source code is free i think. If you have strict code quality requirements like this maybe its worth it to download his extension and do a slight modification to it. I know it already do stuff with private member variables so it shouldnt be too hard to modify.
This extension can do stuff on a file or project basis which makes it easy for you if you have a large number of files to modify.
One easy way of doing this is to just you Ctrl + F & Find and replace. This however doesn't give you the security that you have only updated the relevant variables and could end up changing other thing. But you can always undo the changes easily if they cause problems.
UPDATE
Having read other answers I have tried Ctrl + R + R and this is now the way I will be doing things. I would up vote that answer but can't as I don't have enough reputation yet!
The only way I found is via the Resharper's "Show Potential Fixes" Menu option as outlined by Jowen here.
How to reformat naming styles with ReSharper?
I have a feeling this is going to be really simple. I don't know if I'm just missing a trick here, or searching for the wrong phrases.
I'm looking for a profiling or code coverage (don't really know which category this falls in) that can monitor an application (preferably let me start and stop the monitoring) and count the number of times a method has been called. I've been tasked with optimising some old code and whilst doing so, I've found a few methods that are being called twice or even 3 times, where they only need to be called once.
I have a feeling there could be more of these..
On a side note: I'm actually a big fan of the JetBrains .NET tools. I'm using ReSharper, dotPeek and dotTrace at the moment (but can't find a way to do this). Is it worth looking into dotCover?
Visual Studio 2010 Premium and above have performance profiling tools built in that can do exactly what you're asking.
Here's a blog about the performance tools available in VS2010 Premium/Ultimate.
You're right to consider using 'dotCover'. That's if you want more in-depth code coverage analysis and are willing to invest, then this will be more than suitable. Another alternative is 'NDepend' (http://www.ndepend.com) which I have greater experience with and outputs a large array of metrics.
SmartBear's AQTime Standard (free version) and Pro (pay version) can both track hit counts of methods. I've used AQTime for years and have found it quite useful.
http://smartbear.com/products/free-tools/aqtime-standard/
Not only will it tell you how many times a method is called, but it also can display call trees.
The free version (Standard) really is free - no strings. It is just like the pay version but some of the more advanced features are disabled. But it has enough functionality that it stands on its own as very useful tool.
I don't have any touch or knowledge of dotcover that you are talking about. But regarding number of times a method called, a dumb method to calculate this is create a static integer and increment it in the method. I am not sure what "profiling or code coverage" means. This may sound really stupid if you are asking something else.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
I have to refactor a large C# application, and I found a lot of functions that are never used. How can I check for unused code, so I can remove all the unused functions?
Yes, ReSharper does this. Right click on your solution and selection "Find Code Issues". One of the results is "Unused Symbols". This will show you classes, methods, etc., that aren't used.
It's a great question, but be warned that you're treading in dangerous waters here. When you're deleting code you will have to make sure you're compiling and testing often.
One great tool come to mind:
NDepend - this tool is just amazing. It takes a little while to grok, and after the first 10 minutes I think most developers just say "Screw it!" and delete the app. Once you get a good feel for NDepend, it gives you amazing insight to how your apps are coupled. Check it out: http://www.ndepend.com/. Most importantly, this tool will allow you to view methods which do not have any direct callers. It will also show you the inverse, a complete call tree for any method in the assembly (or even between assemblies).
Whatever tool you choose, it's not a task to take lightly. Especially if you're dealing with public methods on library type assemblies, as you may never know when an app is referencing them.
Resharper is good for this like others have stated. Be careful though, these tools don't find you code that is used by reflection, e.g. cannot know if some code is NOT used by reflection.
As pointed Jeff the tool NDepend can help to find unused methods, fields and types.
To elaborate a bit, NDepend proposes to write Code Rule over LINQ Query (CQLinq). Around 200 default code rules are proposed, 3 of them being dedicated to unused/dead code detection
Basically such a rule to detect unused method for example looks like:
// <Name>Dead Methods</Name>
warnif count > 0
from m in Application.Methods where !m.MethodsCallingMe.Any()
select m
But this rule is naive and will return trivial false positives. There are many situations where a method is never called yet it is not unused (entry point, class constructor, finaliser...) this is why the 3 default rules are more elaborated:
Potentially dead Types (hence detect unused class, struct, interface, delegate...)
Potentially dead Methods
Potentially dead Fields
NDepend integrates in Visual Studio 2022, 2019, 2017,2015, 2013, 2012, 2010, thus these rules can be checked/browsed/edited right inside the IDE. The tool can also be integrated into your CI process and it can build reports that will show rules violated and culprit code elements. NDepend has also a VS Team Services extension.
If you click these 3 links above toward the source code of these rules, you'll see that the ones concerning types and methods are a bit complex. This is because they detect not only unused types and methods, but also types and methods used only by unused dead types and methods (recursive).
This is static analysis, hence the prefix Potentially in the rule names. If a code element is used only through reflection, these rules might consider it as unused which is not the case.
In addition to using these 3 rules, I'd advise measuring code coverage by tests and striving for having full coverage. Often, you'll see that code that cannot be covered by tests, is actually unused/dead code that can be safely discarded. This is especially useful in complex algorithms where it is not clear if a branch of code is reachable or not.
Disclaimer: I work for NDepend.
I would also mention that using IOC aka Unity may make these assessments misleading. I may have erred but several very important classes that are instantiated via Unity appear to have no instantiation as far as ReSharper can tell. If I followed the ReSharper recommendations I would get hosed!
ReSharper does a great job of finding unused code.
In the VS IDE, you can right click on the definition and choose 'Find All
References', although this only works at the solution level.
The truth is that the tool can never give you a 100% certain answer, but coverage tool can give you a pretty good run for the money.
If you count with comprehensive unit test suite, than you can use test coverage tool to see exactly what lines of code were not executed during the test run. You will still need to analyze the code manually: either eliminate what you consider dead code or write test to improve test coverage.
One such tool is NCover, with open source precursor on Sourceforge. Another alternative is PartCover.
Check out this answer on stackoverflow.
I have come across AXTools CODESMART..Try that once.
Use code analyzer in reviews section.It will list dead local and global functions along with
other issues.
FXCop is a code analyzer... It does much more than find unused code. I used FXCop for a while, and was so lost in its recommendations that I uninstalled it.
I think NDepend looks like a more likely candidate.