views:

262

answers:

6

Within Visual Studio 2008, what would be the easiest way to prevent usage of certain functions from being allowed? Specifically, I'm trying to prevent other developers from using "old school" VB6-style commands such as:

  • Len
  • LCase
  • UCase
  • Instr
  • InstrRev
  • Trim
  • Right
  • Left
  • Mid

etc., etc., etc.... The list goes on and on.

I can usually catch these during manual code review, but sometimes things will slip by. Also, it doesn't do anything about old code that doesn't typically get seen.

I know education is probably the best tool, in the long run, but it would be nice to have something to supplement/enforce that.

+6  A: 

I don't know if you can set a compiler flag for this kind of thing, but you can define custom rules for something like fxcop to check for. Here's some documentation on writing custom rules.

swilliams
+1  A: 

You could use a tool similar to FXCop to review code and general warnings or errors in a nant script.

Tom Ritter
+2  A: 

I think this is a management problem and usually technological solutions will fail.

Provide coding standards to developer, enforce it in code reviews. If you have someone in charge of reviewing patches from developers, make sure they reject patches using functions you don't want to see.

Dana
This is what we do now, but without a "technological solution", it's hard to always catch it during manual reviews. And it doesn't address the existing code that isn't making it to review.
Kevin Fairchild
A: 

Perhaps another option is to add a pre-build event to VS that deletes references to Microsoft.VisualBasic.Compatibility. Then any such usage would be utterly hosed :-)

torial
+2  A: 

Hookup FxCop to your build and have it flag those usages. You can write your own rules to enforce your coding standards in an automated fashion.

Mike Post
+1  A: 

Why? Seems like a waste of time to me.

Jonathan Allen