2D Head with a clock as an eyeball.
 Monday, July 23, 2007

I've been struggling with the concept of DI & IoC for a few weeks now. Its not because I don't understand the concept, or the benefits, I struggle with the implementation details. I'm one of those horrible visual learners who needs to see code  before the penny even gets close to dropping.

I found my holy grail of information today, and it was lurking right underneath my nose. I've only recently subscribed to Jeremy Miller's blog and the latter chapters in his series on building your own Composite Application Block seemed a little 'pie in the sky' for me. Ooo boy, was I wrong.

I started at part one this afternoon, and have been reading page after page of excellent content for the DI newbie.

So if you're in the same boat as me, struggling with the question; "How do I create a rich WinForm app, that is comprehensively unit tested, without sacrificing furry animals to the dark gods of the Enterprise Library?" then treat yourself to Jeremy Miller's series on building your own lightweight CAB.


Filed under:  |  |  | 
 Wednesday, July 18, 2007

9421665_f055539a8c_mFound this gem today, and yes - I wrote it.

Its a very simple class, I use it to tell NCover to ignore certain sections of code - fair enough right? Well... here it is.

<CoverageExclude()> _
Friend NotInheritable Class CoverageExcludeAttribute
    Inherits System.Attribute
End Class

Embarrassing. You can see another example of this kind of logic here.

So hands up people - give us your most recent stupid coding moment and make me feel better about myself.


Filed under:  |  |  | 
 Friday, July 13, 2007

I had the pleasure of treating myself to a new phone recently. I had a lot of options, but I finally settled on a Nokia N95. It is a good phone, with good features, and I would recommend it to anybody who wanted more out of their not so smart phone, but couldn't quite justify the use of a PDA. I'm with Robert Scoble, though, I'd prefer to get an iPhone, but that won't be released in Australia until early 2008.

For more info on the N95 visit the NSeries website, it will tell you more about my phone than I can.

There have been a few issues with the phone in regards to the GPS software included with the phone 'Nokia Maps' and there seems to be much forum confusion as to what the deal is in Australia. Hopefully I can clarify the situation:

  • As bought from the shop, you can find POI's, addresses, and calculate routes. It will cost you data using your chosen mobile Internet access point. As you move about the map, it will download imaging via your Internet connection. If you plan a route, you can simulate the route by downloading the voice commands, or you can have the GPS track you as you traverse the route
  • If you want to have real time navigation, you will have to pay around $130 AU for 3 years. This gives you the 3D view and a voice telling you when to turn.
  • The good news is, that you can download the entire map for any country using the abominable Map Loader program available from Nokia. The bad news is that in Australia, you will be lucky to get a download speed greater than 2.2kbps. The maps for Oz are 70MB.
  • Searching for POI's and addresses still uses Internet time, so plan your routes via your home WLAN to save money.

The maps take forever to download, so in the interest of being a nice Internet citizen, I have decided to begin sharing them on the ED2K network. Alternatively you can download it from me directly.

You will need something to open .rar files - I highly recommend WinRar.

To be honest, for the most part, Google Maps on the mobile is a nicer all round experience, but until it starts using the in built GPS, it is still a toy. If you want something to use in the car, go get yourself a dedicated unit, the N95 has better POI's but it still doesn't come close to the TomTom One XL.

Personally, I plan to use the GPS feature for bush walking, and Nokia provides an excellent route stat application called Sports Tracker. With it you can graph your movement, and save the results in Google Earth compatible files, XML, CSV. For this, the N95 absolutely rocks.


Filed under:  |  | 
 Thursday, July 12, 2007

For those of you who like to be early adopters, and are also masochistic enough to be reading my blog AND are reading it from a 64 bit version of windows you can now take pleasure in trying out the latest beta of Microsoft's Live OneCare anti virus solution, now available for 64 bit versions of Vista.

If your keen to jump into the beta program - here is the link.


Filed under:  | 
 Wednesday, July 11, 2007

I often get to play the maintenance role in my coding life, and I actually enjoy it, as I get to see how others tackle certain problems. I also like to challenge myself by fixing bugs with the smallest footprint possible. In doing so, I find a lot of common things that bring down the 'maintainability' of a class. I thought I'd share some pain that I encountered today.

Designer Death

All too often I find code that roughly translates to this example:

internal class MyForm : System.Windows.Forms.Form

   MyClass _myClass; 

   public MyForm() 
   { 

      _myClass = new MyClass(); 
      _myClass.MyPropertyChanged += DodgySideEffectEventDrivenCode; 
      _myClass.MyProperty = new object(); 
   } 

   internal void DodgySideEffectEventDrivenCode(Object sender, EventArgs e) 
   { 
      //Lets do something that requires, ooh I dunno....SQL access 
   }
}

I won't go into all the other reasons why this could be seen as bad code, but for the purpose of the example, changing DodgySideEffectEventDrivenCode to look like this can save a whole lotta WSOD's…

internal void DodgySideEffectEventDrivenCode(Object sender, EventArgs e) 

   if (this.DesignMode) return
   //Lets do something that requires SQL access, but only if we aren't in design mode
}

Poor Private Properties

The following is an example of a useless property. There are precious few situations where this would be beneficial to a class.

private static CultureInfo CC

   get { return CultureInfo.CurrentCulture; }
}

Why not use a private readonly field? While I admit there is the odd place where you might insist on a private readonly property, it is the exception rather than the rule. Now, I know Properties look cooler from the Intellisense dropdown, but c'mon, surely this is saving you some time:

private readonly static CultureInfo CC = CultureInfo.CurrentCulture;

Personally, I think the proof is in the IL pudding…

.field private static initonly class [mscorlib]System.Globalization.CultureInfo CC

Compare that to the IL of a readonly property get method:

.method private hidebysig specialname instance class [mscorlib]System.Globalization.CultureInfo get_CC() cil managed
{
    .maxstack 1
    .locals init (
        [0] class [mscorlib]System.Globalization.CultureInfo CS$1$0000)
    L_0000: nop
    L_0001: call class [mscorlib]System.Globalization.CultureInfo [mscorlib]System.Globalization.CultureInfo::get_CurrentCulture()
    L_0006: stloc.0
    L_0007: br.s L_0009
    L_0009: ldloc.0
    L_000a: ret
}

Boolean Badness or Enumerate Early

Sometimes coding isn't enough; sometimes you need to express your intent explicitly. Take the following function declaration which clearly does not:

internal void SetUIState(bool value)

and its usage:

SetUIState(true);

Can you tell how this function will work? Personally I like comments and documentation – and they would help, but self documenting code is worth a page of English documentation. For example:

internal enum UIState

   enabled, 
   disabled,
}

internal void SetUIState(UIState state)

Combined with a decent IDE, the usage and effect becomes apparent:

SetUIState(UIState.enabled);

An even simpler approach would be to just name the function to imply the usage of the state parameter in the first place. I.E

    EnableUI(true);

Personal choice comes into this a lot, but I think we can all agree that it's all about taking care with naming.

On that….

Unchanged UI

If I ever see another TextBox control named 'TextBox1' I'm going to have to hurt somebody. Seriously though, if you have labels and other miscellaneous controls laying about that you don't need to name because you never reference them in code, and you are using VS 2005 or greater then consider the following approach:

  • Use your control key and select the lot of them.
  • Move over to the properties window and set the GenerateMember property to false.

This will keep the controls initialization local to the InitializeComponents routine, thus reducing the clutter in Intellisense and other areas in the IDE quite significantly.

For the rest of your controls and objects, pick a naming convention, and stick to it like glue.


Filed under:  |  | 
 Saturday, July 07, 2007

  Well, I got through most of Saturdays presentations, unfortunately I had to miss the final two on Microsoft CRM and Expression Designer respectively. However the talks I did manage to attend were very useful, and overall I am pleased by the level of discussion at the very first Code Camp SA.

The presentations for the 07/07/07 included the following:Peter Griffith from ADNUG, master of ceremonies for CCSA

The highlight for me today was definitely Mitch Denny's insight into surviving the transition to using TFS for real world development. He had some excellent advice on how to virtualize your TFS server and build servers, how to get continuous integration going, and even some insight into how Readify tackled some of CI's issues in TFS (namely check in monitoring, build quality transition control and build cleanup).

Dr. Michael Baker presented some thought provoking examples on how to start implementing Programming By Contract techniques in your applications, although I have to admit that I thought the presentation would go in a completely different direction. I guess I should have known, but I was expecting to hear about technologies like Thinktecture's Web Services Contract First and associated methodologies.

Dave Glover in his typical, upbeat and enthralling style delivered an excellent introduction to Silverlight, Expression blend and Popfly. After seeing all this I just want to get going with Popfly on something like Microsoft Surface and start feeling the minority report goodness. Very exciting for the mash up scene.

I do owe an apology to Allan Baird et al, from the IT faculty of UniSA, I have had some less than stellar remarks regarding a university education in IT, however it seems that things are starting to look up with the likes of Allan at the steer. He informed the group of a commitment to start teaching Microsoft .NET technologies in core subjects in 2009 and I think this is an excellent step forward for our local IT education prospects in Adelaide. It also appears they are making great efforts to redress the imbalance of female personell in our industry. Not only that, but they are attempting to attract younger crowd to the IT scene in general.

All in all, it was a fun yet instructive day, good to catch up with some previous acquaintances from Code Camp Oz and to meet new people. Thankyou so much to UniSA, ADNUG and the Goodwood 3rd Scout group for putting on a great set of presentations. I'm sure tomorrow will be equally as good.

* sorry Jeff, couldn't get a decent Google fix on you!


Filed under:  |  | 
 Friday, July 06, 2007

Inspired by this recent post about types of programmers, I found myself asking this question:

If you could have databases of information uploaded to your brain, which three would you pick?

I think I'd like to have Google Maps, MSDN and Wikipedia.


Filed under:  | 
 Tuesday, July 03, 2007

Jason recently wrote about ‘building your own’ Vs ‘buying a prebuilt’ PC.

Hot custom 67 by Don Borth.

"I have stopped operating my personal business and now I pay retail for all my hardware instead of going to wholesalers. I have also stopped building my own PCs and my last three purchases have been big name, off the shelf computers. It just isn't worth my time anymore to save a few bucks wherever I can."

I suppose there is a damn good reason why the big names in PC building became big in the first place: They take the pain out of buying and owning a PC. As a fellow system builder from eons ago, I found that two things drove me away from doing it on a grand scale. Firstly, you can’t compete against the 24 hour after sales support of the bigger manufacturers. Secondly, as Jason points out, you are inevitably forced to mix business with friends. I’ve got to admit that it was mainly the former that made it hard, the latter added insult to injury. Because I have chosen not to make a career out of supporting hardware, it is only natural for me to tell friends and family to go and see somebody who is more equipped to deal with their computing needs. I simply am not a hardware support specialist. The story changes dramatically if they would like some advice regarding software decisions (and so does the quote

It’s clear that recommending your friends to go and pick up a cheap PC from Joe’s electronic emporium is tantamount to ending a friendship, but even if Jeff & Scott started building PC’s fulltime for a living I’d probably still build my own.

I still build my own PC's because I'm prepared to take the time to research the combinations (which isn’t all that much) and I'm also prepared to provide myself with the '24 hour after sales support'. If I have a warranty issue, I’m prepared to wait a little longer to get my new part; I have more than one PC anyway. The benefit is that I get to spend more on the areas of the PC that interest me and choose from the widest set of options available. The potential savings, I feel, are a small bonus, perhaps enough to cover my time doing a bit of research on a weekend.

Perhaps the omega geek driven sense of pride of owning my very own DIY desktop scorcher has plunged me into the depths of insanity, but I have come to the conclusion that you can build your own cheap PC and keep it a secret from your friends.


Filed under:
© Copyright 2008 Jim Burger