Posts

Showing posts from May, 2009

String.Replace vs Regex.Replace

Image
I recently ran into a situation where I had to do some string manipulation. I had to replace some bad text with valid text. All this had to do with creating valid xml element names. So we had to string white space and some other invalid characters and replace them with valid xml element formatting. To do this we ended up using the Regex.Replace static method. Simply because there was some complexity involved that would have entailed using more then 1 String.Replace call when we can do it all with one regular expression. This caused some discussion about how heavy the regex class is and when to use it. I decided to do some testing and these are my results. First the code static void Main( string[] args ) { // this is our test value string testValue = "This is a test string"; int count; // run the regex replace DateTime regexStart = DateTime.Now; for( count = 0; count < 10000000; count++ ) { string newValue = Regex.Replace( testValue, &qu

Your code sucks and I hate you

It's been a while since I posted any code. I've been very very busy actually working and haven't had a chance to update the 'ol blog. Today we're getting away from straight code and getting more into the soft side of programming. I read an interesting article on code reviews. You should take a look at it over here: Your code sucks and I hate you Code reviews are something we do every time code gets checked into the main base line. They are important and help ensure high quality of code. However if you don't take some care they can quite easily get out of hand and develop into a personality/pissing contest between people. If you follow some decent guidelines you will find yourself amazed by the results. I know I hated code reviews in the past but have found them very helpful in uncovering bugs before they went into production. It does take some letting go of the ego but if you go in with the right attitude they will make you a better programmer/engineer/