Devlico.Us
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @devlicious

Christopher Bennage

Our WPF book is now available!

September 2007 - Posts

  • Bellware: Classic ASP Syntax is Bad?

    I want to link to Scott Bellware's post on attitudes regarding classic ASP. He makes an excellent point, and I agree with him.

    About four years ago, I remember telling my former employer about the epic superiority of ASP.NET over classic ASP. I could not deride classic ASP enough. Boy, was I a jerk!

    Now, I don't want to return to classic ASP, but I have learned to appreciate it again.  Just as Scott points out, you can have good code in classic ASP and bad code in ASP.NET (quite easily).

    Not too long ago I had to create a classic ASP page for some reason or the other, and I recall thinking being surprised at how simple it was (translate that as "easy").  This reminds a bit of the rediscovery of JavaScript last year.

    So, what's the point of saying this?  I'm not going to starting working with classic ASP again, but the lesson for me is to be more thoughtful in forming my opinions about a technologies. We developers are quite punctilious and we consider our views are as sacrosanct. (I was vividly reminded of this at our Tallahassee Code Camp, as well as being dealt a crushing lesson in humility, but more on that later...)

  • My new little friend, Enum<T>

    I hate ugly code like this:

    MyEnum enumValue = (MyEnum) Enum.Parse(typeof (MyEnum), stringValue);
    

    Too many casts for my taste. Here's my answer (and yes it's so simple that I am embarrassed to post it, but just in case you haven't thought of it yet...)

    public static class Enum<T>
    {
        public static T Parse(string value)
        {
            return (T) Enum.Parse(typeof (T), value);
        }
    
        public static IList<T> GetValues()
        {
            IList<T> list = new List<T>();
            foreach (object value in Enum.GetValues(typeof (T)))
            {
                list.Add((T) value);
            }
            return list;
        }
    }
    

    So the ugliness is converted to

    MyEnum enumValue = Enum<MyEnum>.Parse(stringValue);
    
    kick it on DotNetKicks.com
More Posts

Our Sponsors

Red-Gate!