On Sat, 19 May 2012 09:08:13 -0700 (PDT), Davej wrote:
>
http://en.wikipedia.org/wiki/List_of_tools_for_static_code_analysis#.NET
>
> Is anyone here using a lint-like program for C# ? I just found a bug
> that would be easy to search for: I'd like to see a warning for an if
> that follows another if with no space between them if the second if is
> followed by one or more else if's.
>
> Would Lint or these other style tools have warned about this?
I'm not aware of any tools that would warn about that. I don't even recall
using any version of lint that would warn about that (but it's been quite
awhile, so that's not really saying much), and probably wouldn't use that
feature if I did. There's too much code running around with that pattern
where the code is correct (i.e. someone just didn't bother to put any blank
lines in their code) and dealing with all the false-positives would be IMHO
more trouble than it's worth.
Of course, YMMV. I adhere to the philosophy that the code's not done until
you've stepped through every line of it at least once, and doing so would
immediately reveal an error in code like that. Additionally, a long
sequence of if/else if/else usually points to a situation that is better
handled either with a switch statement or polymorphism. Others without
those philosophies might find such problems come up in their own code more
often and would find a lint warning more valuable.
All that said, if you're thinking about writing such a tool, the new
"compiler-as-a-service" features in C# 5 (coming out with .NET 4.5) may
make it somewhat easier to implement such a thing.
Pete