Wednesday, October 27th, 2010
I ran into a spot of confusion last night doing some TDD on a method that returns an IEnumerable<T>. I was using multiple yield return statements in it which made the method an iterator and not just a normal method. Even though I know how iterators work, I don’t use them enough to remember their [...]
Tuesday, February 23rd, 2010
Is this too obscure? public class MyObject { private MyExpensiveObject _myExpensiveObject; public MyExpensiveObject ExpensiveObject { get { return _myExpensiveObject ?? (_myExpensiveObject = new MyExpensiveObject()); } } }
Monday, February 15th, 2010
I just pushed a pet project of mine up to GitHub today. It’s a port of the original game of Rogue from C to C#. It’s not complete–it doesn’t save your progress and let you continue on later, but it is playable. Now that the actual port is done, I plan on cleaning up the [...]
Saturday, August 15th, 2009
On my new project, I needed to split a method name up into its constituent parts. For Ruby programmers, this is easy: just split on underscores. For us .NET programmers, we need something a little fancier since we like to SquashOurMethodNamesTogetherLikeThis. Here’s a little regular expression that can do exactly that: (?<!^)(?=[A-Z]) That basically says [...]
Tim Barcz is looking for a solution to an interesting problem in his Coding Contest: Create a Programming Pearl post. I decided to challenge myself by writing my solution as a single “line” of code: public static class StringExtensions { private static Dictionary<char, char> _charMap = new Dictionary<char, char> { { (char)8208, (char)45 }, { [...]