.NET, Philosophically

kick it on DotNetKicks.com

Question: Who deserves a kick in the nuts more—the Microsoft BCL developer who brilliantly decided to name his Uri method TryCreate, or the "Sr. Engineer" on your team who neglected to ever use Intellisense and instead decided to drop this steaming gem of useless crap into your already-herniating codebase? (Snippet from a friend's workplace.)

public static class UriHelper
{
    public static bool TryParse(string s, out Uri uri)
    {
        try
        {
            uri = new Uri(s);
            return true;
        }
        catch
        {
            uri = null;
            return false;
        }
    }
}

Really, can you blame the guy? Who knows—maybe he knows better and is actually sticking a big FU to the MS man for deviating from the TryParse idiom. We can always hope.

Speaking of, .NET 4.0 is getting Guid.TryParse() and Enum.TryParse<T>()—a whole five years after someone in the community thought it was a no-brainer. About time. Really. Now, if we could just get Uri.TryCreate() renamed. :)

kick it on DotNetKicks.com

Tags:

Leave a Reply

To include code, use <pre lang="csharp">// code...</pre>, where "csharp" is any language (e.g. "javascript", "html", "xml", etc).