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

Kyle Baley - The Coding Hillbilly

"We are stuck with technology when what we really want is just stuff that works" -- Douglas Adams

May 2008 - Posts

  • Sparring before DevTeach

    'Tis the day before I head out for DevTeach and have already completed my pre-conference ritual with my wife. It's a fun game we play a few times a year called "Why do you do this?"

    I was just settling in for some quality time with Bear Grylls when she starts the first round off with the standard "So you're taking a week off work?" opening. We'd just had a pretty fun day at the beach so her heart isn't really in it. So I counter with a half-hearted "Yep. Should be a fun time" to let her know I'll take it easy on her, too.

    She responds with a biting "Didn't you just start your contract last week?". It's a slight breach of etiquette upping the ante that early but I give her the benefit of the doubt and play along: "Yeah, I cleared it with them before I started. They were good with the time off for this as well as our trip to London next month."

    She gives an appreciative nod at my subtle volley but then her eyes harden for a few seconds while she plans her next move. She throws out a quick "I thought we agreed to cut back on these things" which stuns me for a moment. If I didn't know her better, I'd chalk it up to an amateurish mistake. But in fact, she's looking to buy some time. I'm not letting her off that easy: "We agreed to no such thing and you know it."

    Her delay tactic isn't long but it's enough: "Do you actually learn anything at these conferences or is it just an excuse to get drunk and speak whatever language it is you people speak?" It's a baiting ploy because we both know I don't imbibe but I don't rise to it and instead bring out the heavy artillery in an effort to return to normalcy: "I've done the cost/benefit analysis already and believe I will gain more than I will lose (though admittedly, the benefits are more long-term and intangible). I'll remind you of our agreement that all aspects of my career remain solely to my discretion as long as we remain on this island. We have already received direct benefit of my community involvement in the form of the upcoming book and my last contract being a direct result of my blogging."

    There is more admiration than resignation in her face and the battle is all but won. But she can't resist a parting shot. With a twinkle in her eye, she snuggles up to me just in time to see Bear chow down on a live frog and says: "Oh well, I guess I'll just stay home and watch Brokeback Mountain while you go off 'fishing' with your buddies."

    Kyle the Victor (I think)

  • Good Gestalt!

    The hillbilly recently upgraded his trailer to Windows Server 2008 but it wasn't interesting enough to talk about, mostly because it went so seamlessly. So much so that I'm hauling out a post from my old blog rather instead of relating my experience. But I will say that so far, I'm very happy with it, thanks in part to these instructions.

    The reason I'm regurgitating is because I've been looking at other people's code recently, including some of my own from way back (trust me, that's an "other" person too). And as I scan through it, I was reminded of something: I'm a big fan of white space.

    In coding standards, there is usually much said about things like putting curly braces on a single line and wrapping single line if statements in braces to enhance readability. But for some years now, I've adopted a personal standard that goes a little further. It was after discussions with Simon Watfa way back when I was looking over some code of his and it stood out more than usual.

    I'll start with two examples. The first is a more "traditional" white space scheme:

    private void returnSomeValue(int parm1, string parm2)
    {
        // if, for and foreach
        if(i == 1)
        {
            // Do something
        }
    
        for(int j = 0; j<100; j++)
        {
            // Loop
        }
    
        if(i == 100) return;
    
        foreach(var item in items)
        {
            // Process item
        }
    
        // Function calls
        string theValue = i.ToString();
        theValue = String.Format("The value is {0}", i);
    
        // Casting
        TextBox textbox = (TextBox)Page.FindControl("textBox1");
        string text = ((TextBox)Page.FindControl("textBox1")).Text;
    
        // Square braces
        string[] myArray = theValue.Split(',');
        myArray[0] = "moo";
    
        // Lambdas
        User user = userList.Find(u=>u.Username=="moo");
    }

    And here's the same code with my preferences:

    private void returnSomeValue( int parm1, string parm2 )
    {
        // if, for and foreach
        if ( i == 1 )
        {
            // Do something
        }
    
        for ( int j = 0; j < 100; j++ )
        {
            // Loop
        }
    
        if ( i == 100 ) return;
    
        foreach ( var item in items )
        {
            // Process item
        }
    
        // Function calls
        string theValue = i.ToString( );
        theValue = String.Format( "The value is {0}", i );
    
        // Casting
        TextBox textbox = (TextBox)Page.FindControl( "textBox1" );
        string text = ( (TextBox)Page.FindControl( "textBox1" ) ).Text;
    
        // Square braces
        string[] myArray = theValue.Split( ',' );
        myArray[0] = "moo";
    
        // Lambdas
        User user = userList.Find( u => u.Username == "moo" );
    }

    That is, there are spaces almost everywhere. The only places I don't use them are within array indexes and when casting.

    Fairly minor differences, to be sure but they really help me follow code, especially when it gets particularly dense (in both senses of the word). Coupled with a decent IDE colour scheme (and the hillbilly still *strongly* favours dark text on light backgrounds), I can more easily pick out the meaty parts of the code while filtering out the noise. The nice thing is that this can all be enforced with ReSharper's formatting options and, I think, even with Visual Studio itself, sans add-ins.

    Couple o' downsides, though. I often work on code on my laptop where I don't set the standards. This requires setting up project specific styles in ReSharper depending on how much work I'm going to be doing in it. Bonus points if the project already includes a ReSharper style. But in general, the lesson is: if you adopt a similar coding style to this, *never* contribute to an OSS project.

    ReSharper sometimes actually gets in the way here, too. With these styles in place, I would type the opening parenthesis of a method call and ReSharper would helpfully add the extra space, then the closing parenthesis for me. When there is no space, you can type the closing parenthesis yourself and ReSharper is smart enough to recognize you've just typed what it's already added. That is, it won't re-add the closing parenthesis. But with the space, you end up with two closing parentheses. It's not as much an issue if you get used to using live templates and auto-complete more often but still an annoyance at first.

    As I mentioned in the original post, I can make up semi-lucid reasons why others should use spaces in this way but the reality is: I just like how it looks. It says to me that the author cares about how the code is presented. Or that the author has eyesight problems.

    Kyle the Aging

  • BahaNET Meeting 1: A Recap

    NOTE: This post is about a day and a half late. I could claim that I wanted the event to sink in first but the reality is I was trying to get a handle back on things after a very hectic week. Part of it was a short but very successful trip to NYC. So dense was the wife's and daughter's shopping-to-waking-hours ratio that I'll be looking for sponsors for our next trip (anyone from Visa and/or American Girl in my readership?). Closest I got to purchasing anything of value was walking by a Best Buy after closing and laughing at a fellow who tried to sell me a router for $120, which was over half off the ticket price.

    But that's not what I came to babble about today.

    Encouraged and invigorated. That's what I felt right after the first BahaNET meeting and what I still feel now two days later. Attendance, including myself and Dave Noderer, was a whopping seven people. Experience ranged from an IT Pro looking to get into programming, to a game programmer (watch for Rudolph the Red-Nosed Reindeer for the Wii this Xmas), to a young lady acting as the sole .NET programmer at a local bank.

    It was a very interactive meeting with everyone showing genuine interest in solving not only the problems I lamented last time but a few others. Everyone was active in the discussion, especially at the end. And I got the sense that from these seven people, we'll have a good base from which to grow.

    The main problem I see is simply getting people to see the value of such a group. As such, this was something we discussed for some time. We veered into some unfamiliar territory for me as we talked about some practical ideas as well as some more...ummm...let's say "long term" plans (like a robotics competition).

    There was much talk on how to change attitudes in the country. This, by far, is why I foresee any real change taking several years. In my last post, I talked about people who have no interest in "talking computers" after working on them all day. But as was pointed out at the meeting, that shouldn't be the focus initially. So I'll be tweaking things more toward the social aspects of the gatherings.

    But even with the small group, one of the major benefits of regular meetings like this came up several times. Namely, people learned things that they may not have known before. There was tremendous interest in DotNetNuke as a possible platform for creating websites (which is a common business model in the Bahamas), which some of the attendees had never heard of. This was not the only example of side conversation enlightenment by any stretch either.

    All in all, I believe those that attended will be back and will bring friends. And I got what I wanted out of it: a sense of how to proceed for the benefit of everyone.

    The final pleasant surprise came when I handed out prizes. People were offered a choice of items and not a single XBox game was claimed. Instead, people took Visual Studio licenses, a book on SQL Server programming, and a copy of Communication Server.

    We even discussed the next meeting: May 30 at the same location (IPBS House). Topic will be: Creating a Website in ASP.NET. See you there!

    Kyle the Re-animated

More Posts