I'm working with somebody else's code right now and ReSharper is giving me a lot of warnings about redundant code, such as:
new string[]{xxx,xxx,xxx}
instead of {xxx,xxx,xxx}
)new EventHandler(xxx)
instead of xxx
)System.Windows.Forms.Form
instead of Form
when directives are used)There is a lot of code to work with, so I'm not sure if it's worth going through it all and removing all redundant code.
With that in mind, I wanted to ask if these are warnings that are only there to improve code style (for aesthetics) or do those pieces of code actually perform extra operations and impact performance a little?
It depends.
Abbreviated array initializers I'm pretty sure compile to the same CIL
Explicit delegate creation I'm not so sure, but I'd expect the same performance
Unneeded qualifiers I'm very sure compile to the same CIL.
The computer's time is in general much less important than your time, or the time of anyone else reading the code. Take a piece of code and replace all the int
s with System.Int32
s and it will take longer to read and longer to understand, and those are also important 'performance' metrics.
Programs must be written for people to read, and only incidentally for machines to execute, as a much cleverer person than me once wrote.