I’m constantly amazed by the insightfulness of ReSharper’s suggested refactorings (ReSharper is a Visual Studio Addin from JetBrains I use with C#). Today, I’ve been working on a threading problem where I’m getting crashes based on what seems like not proper locking across threads (they usually show up as some type of ugly update object or enum error).
My code starts like this:
public static List<DbProgressReport> DbProgressReportProperty { get; set; }
(more…)
For the last few days, I’ve been using DevExpress CodeRush and am finding some very useful refactorings. Many I’m not blogging about, but there are a few that I really like. In this post, I’m going to show just two of those refactorings that have been making my code much nicer and easier to write. One is the “Introduce Using” refactoring, and the other is “Convert to Lambda Expression”.
Before I go into the details, I’d just like to disclose that when I was first writing the Silicon Valley Code Camp web site, I was an asp.net and c# newby. I’m not claiming wizard status now, but I have to admit that when I go back and look at some of the code I wrote back then (including what I’m showing below before the refactoring), it’s a little embarrassing. Silicon Valley Code Camp for me as “when I’m not doing real work” web site so I don’t really have the time to go back and clean things up. Now, with CodeRush, it’s easy to clean things up when I see them with very little effort.
(more…)
I’ve recently started using CodeRush with Visual Studio 2010 and am so far very impressed with the convenience it adds to coding. One thing that is very clear is that the creators of CodeRush are real programmers and look very hard for patterns that us developers are constantly doing. As I run into these things that get my attention, I plan on blogging them. Some are just earth shattering, and others, just nice to have. This particular one is a nice to have.
So, say you have code like this:
var sessionAttendeeOds =
new SessionAttendeeODS();
listSessionAttendees =
sessionAttendeeOds.GetByUsername(Context.User.Identity.Name);
(more…)
In this post, I’ll show a simple example of how when you add a parameter to C# method, ReSharper gives you a simple prompting to ask if you want to add a parameter to your method, or create an overloaded method that gives you the flexibility to maintain the old method signature and have the new method.
(more…)
Well, now I know. Here is an example of some code I just wrote:
if (doDeficitCalc)
{
throw
new ApplicationException("Need to implement deficit weight rating");
}
else
{
// Linear interpolation from top of range to bottom for speed
double x1 = rateBreakList[0];
double x2 = rateBreakList[rateBreakList.Count - 1];
double y1 = rateList[0];
double y2 = rateList[rateList.Count - 1];
double frac = weight/(x2 - x1);
double yResult = y1 + (frac*(y2 - y1));
retWeight = yResult;
}
ReSharper correctly warns me that the else statement is redundant as shown below:
(more…)