By

Find redundant code ...

In the early days of the development of toepoke I didn’t have any proper source control management (yeah, yeah, I know, I know :D !)

Anyway the days of commenting out code whilst I try stuff out and using my own source control management system are long gone (thankfully!).

However I still have a lot of commented out code hanging around from those days and I really need to get rid of it and to tidy things up. Thing is there’s load of files and I didn’t fancy going through every single file, so I figured there must be an easier way.

I figured typically I’m commenting out multiple lines of (C#) code, along the lines of this:

// public void SomeLazyCommentedOutMethod() {
//
// }

So all we need to do is search for //{ or // { or basically // followed by anything with { at some point afterwards. Sounds like a regular expression search to me.

Ordinarily my ability to build a regular expression from scratch extends to this. But thankfully even I can cope this one!

(:b)(//)+([a-zA-Z0-9]){

Which breaks down to:
(:b)* = Zero or more tabs or spaces, followed by
(//)+ = One or more slashes (/), followed by
([a-zA-Z0-9])* = Zero or more letters or numbers, followed by
{ = followed by an opening curly brace ({).

So if you bob (:b)(//)+([a-zA-Z0-9]){ into the Visual Studio Find In Files dialog (CTRL + SHIFT + F) and hit Find All you should find most of the areas where you’ve commented out code.

C#

VB.NET

Well I’ve tried (the C# version) on the toepoke codebase and found 158 hits which on the up side means it’s probably working, on the downside I’ve been a naughty boy!

Posted in : vb.net, code, development, tips

Written by
Founder, Developer, tea maker