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

Karl Seguin

developer @ Fuel Industries ottawa, ontario

August 2006 - Posts

  • I'm losing what's left of my hair reading ex-co worker's blogs!!

    Call me mean-spirited, but...

    There are a couple blogs I read from people whom I've personally worked with, and it takes every ounce of strength not to post rude and obscene comments. It's like, they blog about things that more or less make sense, while I'm plodding through their code that looks like:

     
    objCommand.CommandText = "DELETE FROM atable WHERE id = " + Request.QueryString["id"];

     

     

  • Holmes on Homes for Software Developers

    My girlfriend and I watch Holmes on Homes quite a bit (it's on 3 different channels here in Canada). If you aren't familiar with it, it's about this big guy, Mike Holmes, who's a contractor (think houses, not software you geeks!) trying to fix the messes left behind by other contractors. Every episode is basically about a new family who's lives are ruined by the crappy, and expensive) work done by contractors.

    It almost always starts off with a little problem "we noticed some water leaking" and quickly grows into a nightmare - "the foundation wasn't properly laid out so your roof is broken and has snow in it -we have to fix both (and by the way, your electrical isn't up to code)."  I guess there aren't really any laws (in Canada at least) that protect home owners from this kinda stuff - which is one of the things Mike it trying to raise awareness of (and change).

    Every time I watch the show, I'm reminded of the software industry. It always starts off as a "water leak" and ends up as a "redo your foundation".  Eric Wise recently blogged about a good example - and I've seen other similar failures with my own eyes. Shouldn't there be some accountability and/or liability? I think my dream job is to be an software auditor/inspector or something...maybe I can even use the line "your fired!"...oh to dream!

     

     

  • WoW Forums switch from .NET to Java

    This isn't ground breaking news, and I'm sure there are hundreds of sites every day switching between technologies (.NET <--> Java <--> PHP <---> XYZ), but the new Blizzard forums are now powered by apache-coyote/jsp instead of IIS/.NET like they used to be.

    I'd really like to know why the switch though. I mean, I can understand if they have a Java layer they want to re-use (there is some connection between the forums and the game, like authentication), then it makes sense to go to JSP. Although, I seriously doubt that much of WoW is written in Java.

    What bothers me is that under .NET the forums were slow, buggy and not very functional. I cringe at the thought that they might have switched for better performance/functionality. JSP doesn't come close to ASP.NET (unless you connecting to a Java layer or want to ship to multiple platforms). It all comes down to implementation, the first version was badly implemented, this new one is solid. Grats to Blizzard for picking the right technology for their team, what I want to know is, why did they pick .NET in the first place and how bad was the implementation that they had to scratch it and rewrite it (I'm assuming here)?!


  • A good manager

    I've had the experience to work with different types of managers over the years. Nice ones, mean ones, technical experts, technical dolts, "certified". While it might be a no-brainer, in my opinion, a technical manager is the way to go. Obviously, good managers need people and organisational skills, but in the end technical savvy is what's worked best for me. I'm not talking about having been a FORTRAN programmer 20 years ago - I'm talking about up to date with current technologies.

    A lot probably has to do with the type of projects/teams you are working on. As they grow, organisational and people skills obviously become more important.  I've heard that most managers at Microsoft have a direct background in what they manage. For example, you wouldn't find a manager of marketing who hadn't studied it in school and done it for a while in practice. I mention Microsoft because, while I think it's worked great in some cases (Anders, Vick and Guthrie), it's obviously not been their silver bullet (if we believe anything Mini-Microsoft had to say, or look at the crappy Zune marketing).

    If you hire from within your team, you need to realize that not every-one's going to be management material. Maybe in 10 years I'll be ready (maybe not), but for now, I'm still too much of an ass. I don't know much about HR, and I certainly don't envy the difficulties they have in getting good people, so I can't offer much more advice. All I can say is that you'll likely have to spend a lot of effort looking and pay right to have your cake and eat it too. In the end, it's probably well worth it.

    P.S. - I've had technical dolts that have been very effective, but in my experience, it's been the exception.


  • TDD Lesson 4 - I mock you (updated)

    UPDATE: I solved my problem by marking my method as protected internal instead of just internal.

    My adventures through TDD land aren't over yet. I decided to follow Joshua's and Jeremy 's advice and spend some time looking into RhynoMocks.

    As you may recall, in Lesson 3 I decided to start testing near my database boundary by using a factory provider and creating a fake/test implementation. Basically, instead of actually hitting a database, I would store values in memory. It worked really well, but it did require a lot of work - and sometimes I had to spend time thinking about and planning my fake implementation.  I now realize that on top of the extra work, I was also testing a lot more than just "units" of code.

    So I downloaded RhinoMocks. There's definitely a small learning curve - not sure if it's technical or mental. After a bit of playing with it, I'm really getting into it.

    So sticking with the example we've been working on, let's change our DataProvider to a concrete class which relies on an IDataStore implementation to do the database interaction. Our DataProvider now looks something like:

    public class DataProvider
    {
        private IDataStore _store;

        public DataProvider()
        {
           //this is our actual store, which we default to
           _store = new SqlDataStore();
        }
        internal DataProvider(IDataStore store)
        {
            //override the default store...say for testing!
            _store =store;
        }
        public List<Indicator> GetAllIndicators()
        {
            List<Indicator> indicators =  _store.GetAllIndicators();
            if (indicators == null)
            {
               indicators = new List<Indicator>();
            }
            return indicators;
        }
    }


    Looking at GetAllIndicators (yes, I wrote the code BEFORE writing the test, *tisk*), I see at least 2 things I want to test - the store's GetAllIndicators() is called and null is never returned. At first I thought I wanted to test more than just the interaction between my DataProvider and the store, but I quickly realized that (a) my TestDataProvider didn't really test anything more since the implementation isn't real and (b) I'm unit testing DataProvider, not my store.

    So I write my unit test:

    [Test]
    public GetAllIndicatorsReturnsEmptyListInsteadOfNull()
    {
       MockRepository mock = new MockRepository();
       IDataStore store = (IDataStore)mock.CreateMock(typeof(IDataStore));
       //inject my mock object
       DataProvider provider = new DataProvider(store);
      
       Expect.Call(store.GetAllIndicators()).Returns(null);
       mock.ReplayAll();
       Assert.IsNotNull(provider.GetAllIndicators());
       mock.VerifyAll();
    }


    I create a mock implementation of IDataStore - as you can see, I've already gained a lot by not having to implement my own test version. I then say that I expect a call to my mock object and that it ought to return null. Then I go into replay mode, actually execute the code I want to test and verify my expectations.

    Now, suppose I wanted DataProvider.GetAllIndicators to cache the results (I know, i know..caching has it's ups and downs...). I would only expect 1 call to store.GetAllIndicators..so I write my test:

    [Test]
    public GetAllIndicatorsIsCached()
    {
       MockRepository mock = new MockRepository();
       IDataStore store = (IDataStore)mock.CreateMock(typeof(IDataStore));
       //inject my mock object
       DataProvider provider = new DataProvider(store);
      
       Expect.Call(store.GetAllIndicators()).Returns(new List<Indicator>());
       mock.ReplayAll();
       Assert.IsNotNull(provider.GetAllIndicators());
       Assert.IsNotNull(provider.GetAllIndicators());
       mock.VerifyAll();
    }



    The only things I've changed are:
      - Return new List<Indicator>() instead of null (not really necessary), and
      - Call provider.GetAllIndicators TWICE

    I run the test and it fails. I get an error saying store.GetAllIndicators was expected to be called once, but it was called twice. So I go into my code and add the caching logic:

    public List<Indicator> GetAllIndicators()
    {
       string cacheKey = "DataProvider:GetAllIndicators"; 
       List<Indicator> indicators =  (List<Indicator>)HttpRuntime.Cache[cacheKey];
       if (indicators == null)
       {
           indicators =  _store.GetAllIndicators();
           if (indicators == null)
           {
               indicators = new List<Indicator>();
           }
           HttpRuntime.Cache.Insert(cacheKey, indicators, null, DateTime.Now.AddMinutes(10), Cache.NoSliddingExpiry);
       }
       return indicators;
    }


    And my test now passes because _store.GetAllIndicators is only called once.

    All in all, I'm very impressed. I was having a problem mocking a class object that had an internal virtual member. I did use [assembly: InternalsVisibleTo(RhinoMocks.StrongName)], but as soon as I tried to create my mock object, I was getting an exception deep inside RhinoMocks about implementing or overriding a member that wasn't visible/accessible...I don't remember the exact message, but if anyone can help me out, I'd appreciate it!

    Technorati Tags: , ,


    Posted Aug 15 2006, 10:16 AM by karl with 4 comment(s)
    Filed under:
  • Egads! DON'T Bundle VS.NET with VISTA!!

    So there's a discussion going around about bundling a form of VS.NET (likely some Express Edition) with Vista. It started here, and got a response by Dan Fernandez of Microsoft here, with a number of trackbacks everywhere.

    One of the arguments given is that it'll help Microsoft grow the next generation of coders:
    "Part of the appeal of Linux is that you can easily develop and modify stuff. Why not keep the next generation of creative developers by providing them with that opportunity on Windows?"

    To the best of knowledge, Microsoft doesn't have a problem creating new, or retaining existing developers - it's the most developed platform out there, way ahead of linux. So why try to solve a non-existent problem?

    My real problem with all of this is that it goes against what a number of us have been saying here at codebetter.com : PROGRAMMING IS TOO EASY. Some people out there actually want a shortcut on my mom's computer so she can write her own "window manager or even file system". Whatever world some people are living in, I'm jealous. There are too many people out there writing crappy software, way too many writing way too crappy stuff. It's a n honest to god plague that'll eventually boil over and cause some major issues (liabilities).

    If you have a child, or know of one, that you think would like to learn to program, check out the Kid's Programming Language (KPL). I've used it and like it very much - problem solved!


  • Where are the .NET Socket Servers?

    I've been searching the web high and low looking for a robust .NET socket server (specifically aimed at multiplayer gaming, but I'm at the point where I'll be glad to find anything). There are decent codeproject articles that cover the basics, and even a handful of client-server multiplayer games, but I've yet to find a generic and robust server solution - not one! Nothing open source, nothing commercial.

    If you are building a high profile/mission critical servers, say IIS, Apache or a World of Warcraft server, I have no doubt you'll want to use C++. The performance gains and small memory footprints of pointers are key to being successful. But for more modest goals, the benefits of a managed world are huge - can your server really afford to leak memory and do you have the resources to make sure it doesn't? That's why I'm not surprised that there are a handful of Java servers out there which seem to be doing reasonably well - but where are the .NET ones?


  • JetBrains does it again? TeamCity's here!

    Have the good folks at JetBrains done it again? Today they announced the first public release of their newest product: TeamCity. Looks like a build management / continuous integration tool.

    Interestingly enough, it's works for both Java and .NET and seems to plug into most of the popular .NET tools.

    Two issues though. Their homepage states that it integrates with the IDE, but they only mention their own Java IDE...no VS.NET integration?! No Thanks! Also I didn't see SourceGear Vault in the list of supported source control repositories - which makes it a no go for me as well. Of course, it's still in beta, so I'm going to keep my fingers crossed!

    I've been using JetBrain's Resharper for about 2 years now. It provides amazing productivity boosts. I strongly recommend that any VS.NET + C# developers try the fully functional 30-day trial. I think price/performance it's the best money you can spend - flat out.
More Posts