Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does resharper suggest const, static operations?

Tags:

c#

.net

resharper

I was wondering why resharper suggests a method to be static in non static class? Is it for saving the creation of the instance? Is it a matter of performance? also, why does it suggest to 'const' some params? Is it a matter of performance ? I would love to get some explanation

like image 953
Royi Namir Avatar asked Aug 11 '11 05:08

Royi Namir


1 Answers

The other answers are correct, it's just a good practice.

But I want to show how it can benefit you. Often times, when some big method can be made static, it is a hint that there's another responsibility there, which may be best handled by extracting another object for just that task.

It also can have a chain-reaction type effect - say A calls B, both non-static. Now Resharper tells us B can be made static; we let it do its thing. Now maybe A can be made static too. Maybe A is also another responsibility entirely.

This effect has come in handy for me when refactoring older code. It let me see responsibilities and points where I could cut code out without having to sweat over every inch of text.

like image 193
Paul Phillips Avatar answered Oct 19 '22 10:10

Paul Phillips