Archive for the ‘.Net’ Category

Loving the Visual Studio 2008 compiler

Friday, December 5th, 2008

I have been finding lambda and extension methods really helpful in my game port.

Blobs of C styled single linked list code, when changed to generic lists boil down to one line.

like this:

Item item = player.itemsPtr;
while (item != null)
{
    Item next_item = item.next;

    if (item_type == item.type)
    {
        lose_item(item, player); // just removes from linked list.
    }
    item = next_item;
}

to this:

player.items.RemoveAll(item => item.type == item_type);

much nicer.

Microsoft UNPLUGGED - WPF & VS2008

Sunday, November 16th, 2008

I attended the November Unplugged WPF & VS2008 developer session on Tuesday.

JD’s talk was well balanced, and covered the basics of what WPF is, how the UI and UX work.  He avoided only showing the shiny demo screens and dug deeper into Command and RoutedEvents and how the UI and UX are decoupled.

WPF is so big, and a bit of a mind shift from VB6 drag and drop that I’m not sure there is much more that can be demoed to a general audience.

Kirk’s Visual Studio 2008 talk was fantastic.  Lots of keyboard short-cuts for tasks I’m currently doing via the  mouse, so I’m very pleased to learn the key combo’s.

I’m torn between Crtl + . and F8 being my absolute take-away gems, both will be used heavily.  Nice to see a talk about using the tools better.

There were some good give-away’s, an office 2007 license, a wireless mouse and a 22″ wide screen panel.  Of which I didn’t win any.

This has made me more keen to port CotAB to Silverlight, just for the experience of it.

Before the event I attended a MS feedback discussion group.  So funny to see who of the .Net CHCH scene turned-up.  It was good to talk about issues, impressions, and opinions.  I hope Microsoft guys got the value they were hoping to get.

Cedric’s Coding challenge

Wednesday, July 2nd, 2008

I noticed Cedric’s Coding challenge while reading Robert Fisher’s blog.

Here is an interesting coding challenge: write a counter function that counts from 1 to max but only returns numbers whose digits don’t repeat.

For example, part of the output would be:

  • 8, 9, 10, 12 (11 is not valid)
  • 98, 102, 103 (99, 100 and 101 are not valid)
  • 5432, 5436, 5437 (5433, 5434 and 5435 are not valid)

Also:

  • Display the biggest jump (in the sequences above, it’s 4: 98 -> 102)
  • Display the total count of numbers
  • Give these two values for max=10000

Because I love coding problems, I whipped up a C# 2.0 solution which is not as succinct as some of the functional solutions, but it works on a ‘fast enough for me’ time scale.

using System;
using System.Collections.Generic;
using System.Diagnostics;
namespace ConsoleApplication1
{
    class Program
    {
        static bool[] used = new bool[10];
        static int value = 0;
        static void Main(string[] args)
        {
            int gap = 0;
            int last = 0;
            int count = 0;
            Stopwatch timer = new Stopwatch();
            timer.Start();
            int mag = 1;
            for (int i = 1; i < 10; i++)
            {
                foreach (int x in Step(1, mag))
                {
                    gap = Math.Max(gap, x - last);
                    last = x;
                    count++;
                }

                mag *= 10;
            }
            timer.Stop();
            Console.WriteLine("Count: {0}", count);
            Console.WriteLine("Gap: {0}", gap);
            Console.WriteLine("Time: {0}", timer.Elapsed);
            Console.ReadKey();
        }
        static IEnumerable<int> Step(int start, int mag)
        {
            for (int i = start; i < 10; i++)
            {
                if (used[i] == false)
                {
                    if (mag == 1)
                    {
                        yield return value + i;
                    }
                    else
                    {
                       used[i] = true;
                       value += mag * i;

                       foreach (int x in Step(0, mag / 10))
                       {
                           yield return x;
                       }

                       used[i] = false;
                       value -= mag * i;
                   }
               }
           }
       }
    }
}

Giving the following output (for 1 - MaxIn, as compared to 1-10,000 in the original challenge)

Count: 5611770
Gap: 10469135
Time: 00:00:02.8350765

Finding reference .dll’s

Friday, March 14th, 2008

I am currently upgrading our build process from .bat files to CruiseControl.Net projects.  Mostly C++ projects but a few VB and one C#.

The C# project has a reference to NUnit.Framework.dll, and every thing worked well on the developer machines and the build server when building Visual Studio or using devenv.exe. But I have changed to using MSBuild.exe because that is what the CruiseControl.Net/NAnt example I’ve been following does.

When MSBuild.exe is ran at the command prompt the C# project runs fine, but when run from the CruiseControl.Net service I get the following errors:

errorCS0246: The type or namespace name 'NUnit' could not be found (are you missing a using directive or an assembly reference?)

After lots of hair pulling, I noticed one of the my C# projects had a <HintPath> element inside a <Reference> element.  The example was a relative path, but changing it to a full-path was required for my situation, as the projects are loaded to a different location on the build server.  So, in my C# project’s .csproj file, I have added this block:

<Reference Include="nunit.framework, Version=2.4.2.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>C:\Program Files\NUnit 2.4.2\bin\nunit.framework.dll</HintPath>
</Reference>

I’m not sure how you would set the <HintPath> element from inside Visual Studio.

Missed the Summer Road Trip

Friday, February 15th, 2008

I was planning to attend the 2008 Summer Road Trip today, but the work meeting I was just in overran.

The presentation has started, I’d have to find parking in town, and it’s raining.

So I’ll miss becoming edu-mi-cated about SQL Server 2008, Visual Studio 2008 or .Net 3.5

I’ll also not win one of two Windows Home Servers.

*snap*

Guess I’ll just get back to work…..