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

Karl Seguin

.NET From Ottawa, Ontario - http://twitter.com/karlseguin/

June 2007 - Posts

  • Resharper 3.0 and Orcas - No False Advertising Here

    I'm a big fan of resharper. If you go to download 3.0 and read the installation instructions, they state very clearly that although it'll install in Orcas, it doesn't support any of the 3.0 language constructs.

    And that's the absolute truth. It installs fine, but doesn't support any of the constructs...which means...

    1 - The background compilation will report numerous errors which aren't really errors
    2 - The formatter will annoyingly auto-format code it shouldn't
    3 - Some of the tips (alt-enter) will break your code

    My point? I thought...well, I don't know what I thought. I thought I'd install it, get all the typical resharper goodness and by on my merry way. But the truth is I had to uninstall it because it was really getting in my way.

    Now..you specifically have to tell it to install for Orcas...so if you have 2005 and Orcas side by side, you can still (and should) install it for 2005. But I thought I'd save the other brace souls out there the pain.

     

  • AlphaGeek? Puleezz!

    I don't believe in AlphaGeeks.

    If you're a book publisher, I have no doubt that they are a very real market segment and probably one worth watching very closely. It might even hold true for things like internet browser trends. But for the rest of us, I think all the recent talk about AlphaGeeks and Microsoft has been nothing short of FUD. Remember when Red Hat was going to take over the desktop? Today it's Apple or Ubuntu. Maybe they will, but no one with a brain thinks it'll happen very quickly. Even if Ozzie doesn't shake things up, there are just too many units within Microsoft still doing great work, despite the many that aren't.

    The vast majority of programmers aren't agile nor should they be- they have lives to live outside of continuously relearning and bills to pay. Java was really cool once, yet somehow Microsoft continued to amass an army of programmers. I think Ruby's increasing popularity will adversely affect non-Microsoft technologies more than anything else. I've heard that the MacOs resurgence has hurt the Linux market share a lot more than the Microsoft one.

    On top of all that, Microsoft's huge push to .NET, it's position on VB6 and the continuous changes and improvements being made to C#,VB.NET and the framework, is by far more aggressive and agile than what we are seeing from the other players, including ruby (maybe 2.0 will actually ship in 2007).

    With all that said though, Scott Hanselman's post about "What you're not getting about Ruby" is dead on. He's level headed and doesn't say, what amounts to, "learn ruby or you'll be unemployed and unemployable next year." Rather he says you should keep your skills sharp, and for those of us who've been working in .NET for the last 6 years, learning Ruby will definitely be useful.

    Ruby certainly is an interesting language to learn…but, as have been said by others, the rumors of Microsoft's death have been wildly exaggerated.

  • My .NET Wishlist

    Following is a list of features that I wish were available to me as a .NET developer.

    Distributed Caching
    .NET's built-in caching capabilities, especially for ASP.NET developers, was a major new enhancement for web developers. When properly leveraged, both the output caching and programmatic caching API can lead to awesome performance. Unfortunately, as a system grows and performance really starts to matter, the built-in caching quickly falls apart - it doesn't scale whatsoever. .NET caching needs to be more pluggable and ship with a distributed caching system. I work with numerous load balanced solution and only rarely use the built-in caching mechanism because your caches will quickly fall out of synch.

    Commercial Alternatives: Alachisoft NCache (not familiar with it, but lots of people talking about it)
    Open Source Alternatives: memcached

    For the curious, I've read that Facebook is using 200 memcached servers.

    Less language features, more IDE features
    I don't know what the story for Orcas is, but the tug-of-war between the IDE and the language teams has really sucked. Many things that should be IDE features are currently language features. Regardless of how you feel about background compilation, refactoring or edit-and-continue (I'm probably missing a couple), these things should be baked into the IDE with the language able to hook into it. Supposedly it's something being worked out so hopefully the story will get better soon.

    Rethink the ASP.NET page model/life cycle
    Thinking beyond the common request to implement an MVC pattern, I'd be great if the ASP.NET team could rethink the current model and life cycle. It leaks badly in any complicated scenario. 6 years after its release, I still don't fully understand it, and I'm ready to bet that I'm in the overwhelming majority. The only time it doesn't leak is when you don't need any of the fancy stuff it tries to do. I'm almost at the point where I just don't use .NET if I'm building a heavy web-based application. Forget learning an O/R mapper, test driven development or understanding domain driven development, the single best thing any ASP.NET developer can learn right now is MonoRail.

    Silverlight Physics and Network API
    I might be biased about this, but silverlight without a built-in physics engine and networking stack makes it useless in a lot of cases. It's a young product with a lot of growth potential, but it looks like the early versions will ship with some key features missing (I'm not just talking about the alphas...but the final 1.1 release).

    Safe Thread-Local Storage
    I know there's a lot of confusion about this, but I want an ASP.NET-agnostic method for storing data for a request. It isn't the end of the world, but code like the following, even if it's hidden away, bugs me:

    SomeContext context = (HttpContext.Current == null) ? (SomeContext) Thread.GetData(Thread.GetNamedDataSlot(_dataSlotName)) :
                                                          (SomeContext)HttpContext.Current.Items[_dataSlotName];

    Probably the reason I want this is because too many people (including myself) got burnt badly bythis.

    Better handling of DBNull
    It was hoped that nullable types were gonna make it easier to work with DBNull, but, to the best of my knowledge, that never worked out. There should just be something like the CSLA.NET's SafeDataHandler built into ADO.NET.

    Better IDE Help
    I find the built-in help horrible. Opening up firefox and googling something is _always_ faster and more accurate than hitting F1. It boggles the mind. In fairness, I've used a number of IDEs and in each case the help section is always the worst - VS.NET's is a lot better than most.

    .NET on Linux As a first class citizen
    Nothing more to say about this. .NET on Amazon’s EC2 would rock.
     

  • Tweaking .NET's Cache API

    Much like I typically wrap my DataReaders in the CSLA.NET's SafeDataReader to better handle DB Null's, I've taken to wrapping .NET's built-in Cache object in order to improve the API, decreasing my code's coupling and improve testability.

    Three things always bug me about the Cache's API:
       1 - Inserting null data throws an exception
       2 - Never seems to have the right overload
       3 - Repetitiveness of creating composite keys


    First thing to do is create an ICacheManager interface, we’ll keep it simple:


    namespace CodeBetter
    {
      public interface ICacheManager
      {
        void Insert(string key, object data, TimeSpan slidingExpiration, params object[] args);
        void Insert(string key, object data, DateTime absoluteExpiration, params object[] args);
        void Insert(string key, object data, CacheDependency dependency, DateTime absoluteExpiration, TimeSpan slidingExpiration, Priority priority, params object[] args);
        T Get<T>(string key, params object[] args);
      }
    }


    In my experience, I almost always reuse the same Insert overloads - I rarely ever set a priority (let .NET manage its own memory usage I say) or specify both an Absolute and Sliding expiry, and not too frequently specify a CacheDependency. So I create a couple Insert that'll get used 95% of the time without having to specify a bunch of null/defaults AND a one that lets me specify everything.

    Internally I handle null data by simply returning out of the insert:

    if (data == null)
    {
      return;
    }


    Finally, you probably noticed that in each case above I have a params object[] args. That's because I often find myself using composite keys, something like:

    string key = string.Format("UserById:{0}", userId);

    By letting my insert handle that, my API is a bit cleaner. (A nice thing about params is that you don't have to specify a property at all)

    Here are a couple sample calls:

    Insert("UserById:{0}", user, TimeSpan.FromMinutes(10), user.Id);
    Insert("SystemConfiguration", configData, DateTime.Now.AddHours(2));


    And here's the relevant code:

    public class InMemoryCacheManager : ICacheManager
    {
       public void Insert(string key, object data, TimeSpan slidingExpiration, params object[] args)
       {
          //call overload...
       }
       public void Insert(string key, object data, DateTime absoluteExpiration, params object[] args)
       {
          //call overload...
       }
       public void Insert(string key, object data, CacheDependency dependency, DateTime absoluteExpiration, TimeSpan slidingExpiration, Priority priority, params object[] args)
       {
          if (key == null)
          {
              throw new ArgumentNullException("key");
          }
          if (data == null)
          {
              return;
          }
          if (args.Length > 0)
          {
              key = string.Format(key, args);
          }
          HttpRuntime.Cache.Insert(key, data, dependency, absoluteExpiration, slidingExpiration, priority);
       }

       public T Get<T>(string key, params object[] args)
       {
          if (args.Length > 0)
          {
              key = string.Format(key, args);
          }
          return (T)HttpRuntime.Cache.Get(key);           
       }   
    }



    Although I find the syntactical improvements pleasant, the real benefit is with the introduction of the ICacheManager interface I've reduced my system's coupling and can easily create an IMemCachedMemoryManager. It's also easy to Mock up, and plays nice with tools like StructureMap:

    MockRepository mock = new MockRepository();
    ICacheManager cacheManager = _mock.CreateMock<ICacheManager>();
    IDataStore dataStore = _mock.CreateMock<IDataStore>();
    ObjectFactory.InjectStub(typeof(IDataStore), dataStore);
    ObjectFactory.InjectStub(typeof(ICacheManager), cacheManager);

    User user = new User { UserId = 34 };
    using (_mock.Ordered())
    {              
        Expect.Call(dataStore.LoadUserFromCredentials("username", "password")).Return(user);
        _cacheManager.Insert("UseById:{0}", user, TimeSpan.FromMinutes(10), user.UserId);
    }           
    mock.ReplayAll();
    Assert.AreSame(user, new Repository().CreateUserFromCredentials("username", "password"));
    mock.VerifyAll();

     

  • Jeremy's right...being a Microsoft developer isn't that bad..

    I have my share of problems with Microsoft, and Martin Fowler is right that there seem to be a conscious effort to discourage tools that enable enterprise developers and agile developers.

    But...Jeremy is right that being a Microsoft developer isn't that bad, yet people seem downright hostile to his positive and realistic outlook. Like Jeremy, there's a strong economic reality for me (and likely most other .NET developer) to stick with Microsoft. That doesn't make us sellouts.

    He's also right that things are getting better each day, both in the OSS community and in general best practice awareness. Yes we take a few steps back, like the silliness of MSTests and the disgusting TDD.NET fiasco, but that's just life. We have too many pompous old frogs who think their way is the only way and will never stop BITCHING no mater what Microsoft does. NEWS-FLASH you aren't Microsoft's only customer...they really do have Morts, it's a significant part of their business, and they aren't going to give up on it...LIVE WITH IT.  I can agree that lately they've seem to be trying to turn all of us into Morts, but that'll balance out.

    He forgot to mention how great some people at Microsoft really are. Guthrie, Hejlsberg, Vick and Box are just a few of the handful of extremely talented and passionate individuals. I can't imagine the type of balancing act ScottGu and PaulVick need to do to keep their extremely broad audience happy. I doubt anyone of us, Martin Fowler or Tim  O'Reilly included, would do any better.

     

More Posts

Our Sponsors

Proudly Partnered With