Works on my machine

Works on My Machine http://jcooney.net/archive/2007/02/01/42999.aspx (via http://www.codinghorror.com/blog/archives/000818.html). There are of course several responses to this

Pointy Haired Boss
Great, a new formal acceptance program for protyping code testing. I just hope its compatible with ISO 9001 and Six Sigma.

Manager
Oh no. Another piece of certification that my staff must comply with. We will never hit the next release delivery date with this extra overhead.

QA
Wow. Dev are doing some testing… Hmm, what’s this bit? Optional? Testing isn’t optional.

Developer
Professional reputation 🙂 snigger.

Advertisement

Has Microsoft released Vista, I didn’t notice

Alas poor marketing team, I knew them well

Until now I’ve been wondering what happened to Microsoft’s marketing team. Admittedly I don’t believe that I belong to their target audience.

I don’t read newspapers so I’ve probably missed those full page spreads showing the new glass interface in full colour. I tend to go and get my news either from news.bbc.co.uk which I hope has less of the usual this or that political bias than most. Or if I really want to know by watching the Press Associations RSS feeds. These feeds have the advantage of having NO editorial or comment or anything really. They consist of really short facts (usually). I particularly don’t like the free rags foisted onto you every night, as these seem to consist solely of advertising, celebrity photos/exclusives and a small portion of content recycled from the mainstream newspaper which is coincidentally owned by the media moguls who pay for these advert/celeb rags. (Although I must admit they do provide a source of revenue for London taxi drivers. For without all those distributors standing on every inch of the pavement, we might actually make our trains and tubes on time.)

I do get a very small window of opportunity to watch tv, certainly no more than 1 hour a night, and averaging far less than that, but I have caught the “Wow” advert once. I must admit I liked it. I’m not going to rush out and buy Vista just because of it, but it was a nice piece of advertising. It certainly fell into the classic English advertising of not being brash and upfront, but instead trying to get a brand formed in your mind. All those technical and social revolution milestones, wow this Vista must be a huge positive change. Ahem.

What I have seen is all the bill board advertising. This I have no choice but to read. The tube station halls either have these 6’x4′ images jump out on you as stride down the corridor, or hold your eye while you wait for the “tube muggle” to move over to the right with their suitcase. I particularly like the two english comedians

  • I was built for spreadsheets and text editors – I was built for music and video
  • I was built for the office – I was built for the home
  • I suffered from 14,000 (2) viruses last year – I suffered from none

Hold on a moment, those adverts are on a white background with black text, and they have a fruit like logo in the bottom. Oh no I’ve been reading Mac propoganda (1). So where is Microsoft? Did they miss me?

Well actually no

Now if you found this post, you’ve found this site. If you should decide to read around, you will probably come to one of two conclusions.

  1. Wow this guys sure does know a lot about C#, DotNet and programming on Windows.
  2. This bloke is a sad geek who spends all his time on computers and has no other life.

Either way the problem is simple. Anything I can see in an advert I have already been reading on the old Windows Vista site. I deliberately did not download the Vista Beta purely because I knew I would be hooked, and so instead I have spent a fair portion of time keeping up with Longhorn. One reason I am already fully conversant with what is coming in Vista, because I don’t spend my days reading the adverts and celebrity photos in those free papers. Thing is though you could be too, except it appears to have gone. The marketing guys have been and taken away all the detailed information and replaced it with the celebrity photos edition. Like a size zero model it looks good, but there’s less under the surface than you want.The more you look the less you find.

Today Vista marketing hit me square in the face

Lunch time today I needed a break. I had no urgent issues to address, no clients concerns and no meetings from 11am to 2pm. I had some time spare, a commodity rarer than gold dust, that occurs less frequently than both of my children being angels at exactly the same time. I took a wander over to PC world.

To me PC world is a near utopia. It has all those glittering pieces of hardware in the flesh, just calling out to you to buy them, but you must not. You can buy them cheaper elsewhere. The virtual land of Amazon is a short URL away and provides you with all the pictures, lots of information, no salespeople,better prices and the spec you actually want. Alas, Amazon is virtual and PC world is real.

Today it was a Vista heaven, and after having a play on actual Vista laptop I know know what Microsoft marketing have been up to. Almost every single laptop and desktop was running Vista. Theoretically I can see what all the hype is about and go Wow. Well actually more like wow, erm . It was pretty, it had glass, but it is just an OS. Sorry but it is. Now my OS does three things for me, that I can appreciate.

  1. It hibernates my session when I close my laptop (although not all the time if I am debugging in VS2005).
  2. It takes up a small line at the bottom of the screen with the Start Bar.
  3. It lets me change programs with Alt-Tab.

Everything else it does is invisible, I just take it for granted. So I really need to spend more than 10 minutes playing with a laptop in a store. So my first impression is this

  1. I didn’t get chance to hibermate
  2. The line at the bottom is black not blue, and you can run the sidebar on the right.
  3. Alt-tab now works an in a funky way, but the really pretty window switcher is via the mouse.

So will I be upgrading to Vista

Well… yes. I mean there is absolutely no chance that I won’t at some point. At the very least my employer will upgrade and I will use it then.

Am I going to rush out and buy a copy… No. There’s no reason to spend money updgrading my current laptop which is five years old, has one shift key and one USB port that don’t work. I’m not afraid of going through the upgrade. I bought my Tecra 9000 as the 2nd one (supposedly) into the UK. It came with Win2K and I went through driver hell getting it working with XP. This time I’m not in such a rush.

However what does excite me is the opportunity to run Vista on a tablet. New OS on new Hardware with new hardware and funky new features. Maybe I’ll stop that lump of bone growing anny bigger before it becomes RSI. Lots of talk about how much better Vista is for handwriting recognition which it needs to be as my handwriting is appalling. I’ve run Pocket PC’s for years until I bought my laptop and that was always hit and miss.

So thanks Microsoft. When the hardware manufacturers get me the tablet spec I’m after I’ll be buying nto your new OS. Until then, well I would say don’t waste your money on the advertising, but it looks like you aren’t.


(1) Not that I am adverse to Macs, there just isn’t much call for them in the average real time processing system that handles large sums of money a day.

(2) This figure is probably wrong. Sorry wasn’t paying that much attention as the 8:40 was late again and another hoard of fake business types (3) were wheeling their briefcases into everybodies way on the tube.

(3) You can tell fake business types from the real ones in one simple step. Ignore the BlackBerry, mobile, laptop, corporate suit or even the miniature filing cabinet/massive briefcase on wheels. When they step off the train/tube are they already travelling at top speed? Those are the ones who are driven and have to get things done.

(4) Yes I have read Pratchett. How did you guess?

CLR integration – SQL

Just written my first C# SQL function, here it is in all its glory.

[Microsoft.SqlServer.Server.SqlFunction]
public static DateTime GetSunday(DateTime original)
{
    DateTime result
= new DateTime(original.Year, original.Month,
        original.Day
((int) original.DayOfWeek),
       
0, 0, 0);
   
return result;
}

Then I went and found out how to really go to town. http://msdn.microsoft.com/…/sqlclrguidance.asp, so here is my 2nd function (and helper)

 

[Microsoft.SqlServer.Server.SqlFunction
    (FillRowMethodName
=FillGetAllDates,
    TableDefinition
=Date datetime)]
public static IEnumerable GetAllDates(DateTime start, DateTime end)
{
    DateTime date = start.Date;
    List
<DateTime> result = new List<DateTime>();
   
while (date <= end)
    {
        result.Add(date);
        date
= date.AddDays(1);
    };
   
return result;
}

public static void FillGetAllDates(object row, out DateTime date)
{
    date
= (DateTime) row;
}

IEnumerator and Foreach

I wanted to write a simple post about List enumeration and suddenly realise that here we as developers, are about to enter a pradigm shift. No longer is the default to develop for a single processor, threading will not be something that clever programs use. Almost everything is going to require scaling and queuing.  Why? Well here comes Core Duo. Two processors on a single piece of silicon. In fact I even read that servers are going to be offered with four Core Quad Chips. Welcome to the “many core” era.

I almost always use foreach for all list processing. Of course as we move into a many core world the standard concept of foreach just wont cut it anymore. Consider the following.

foreach (Data x in List<Data> list)
{
    Action.Do(x);
}

That just doesn’t take advantage of this extra power. It keeps all the processing on a single thread on a single Core of a single CPU. Looking for bottlenecks, start right there. Of course the reason we use this is because of its simplicity. Everyone can read this. It makes sense.

However there is an answer, and as usual it isn’t anything new. In fact it is the GoF Visitor pattern, and it’s already it the code above (sorry must stop cheating).

By defining the operation that we want to perform outside of the loop, in this case Action.Do(x); then we allow ourselves the opportunity to change the loop.

foreach (Data x in List<Data> list)
{
    Action.BeginDo(x);
}

Which only leaves us with one problem? How do we know when they are all finished?

Update:
I think just missed my own point here. Why? Well this is exactly the same thing that Eric Sink wrote about http://software.ericsink.com/entries/multicore_map.html in response to Joels post http://www.joelonsoftware.com/items/2006/08/01.html.

InternalsVisibleTo

nUnit integration is made so much better with the InternalsVisibleTo attribute. Declare this in the assemblyInfo of the class you want to write tests for and specify the nunit dll that you want to be able to acccess the internals. [assembly:InternalsVisibleTo(“nunit.xml.whatever”)]

Why does this help?

Probably the best way to illustrate this is with an example. I have a class in an assembly which takes an object model, converts it to XML and then passes it into a webservice. My unit tests want to confirm that the serialization always work, not the webservice. My interface does not expose the XML at any point.

However with this attribute I can now expose the XML via an internal property, and pick it up as a test.

Sometimes you don’t get much credit except in the debug logs

I recently re-engineered my primary responsibility at work and when asked for a marketing spin on the work I said that ExcelRTD could now update 3 million cells per second in Excel via IRTDServer. This was dismissed as being over confident and I must admit the biggest problem is that although I can get the info to Excel in the time, Excel will then sit for a long time, say 5–15 seconds digesting it. So the only real way I can show this is by looking at the Debug output, where I time the entire RefreshData() operation. i.e.

public Array RefreshData(ref int topicCount)
{
   Win32Extra.HiPerfTimer timer = new Win32Extra.HiPerfTimer();
   timer.Start();

   try
   {
      Array result;
      …
   }
   finally
   {
      timer.Stop();
      Debug.WriteLine(“RefreshData @” +DateTime.Now.ToLongTimeString()
         +“, Count=”+topicCount.ToString()
         +“, in |”+timer.Duration +“| ms”);
      return result;
   }
}

}

So that of course means that my values show the whole time I can influence. Unfortunately they also time while the process is switched out, so heres my results from opening a huge sheet. The good are in Bold and the bad are Italicised.

Check: 1 sec was 991.611224331584ms
RefreshData @11:37:18, Count=7, in |11.0257029873909| ms
RefreshData @11:37:26, Count=5861, in |77.4053685594119| ms
RefreshData @11:37:53, Count=1453, in |1.87537801592102| ms
RefreshData @11:37:55, Count=1649, in |3.066311500484| ms
RefreshData @11:37:57, Count=218, in |0.112025411050846| ms
RefreshData @12:02:49, Count=44672, in |21378.2092416774| ms
RefreshData @12:02:59, Count=0, in |442.494506983429| ms
RefreshData @12:03:01, Count=84656, in |440.760208350503| ms
RefreshData @12:03:09, Count=0, in |0.0282158765988415| ms

Damn, the peak rate has dropped by a factor of four. Now its only 3/4 million per second. If only I could find out why? Oh well that’s the joy of working in multi-tasking operating systems.

Recovered Post: Visual Studio Assembly Cache

All,

In the various builds we all have the ExcelRTD project which has always seemed to work magically when it comes to installing via COM itself for debug purposes. Some not so good news, this is likely to break when you start moving to the next version with Bonds.

 

Monitoring a Debug Run

Following a lengthy session with FileMon I discovered that the IExcelRTD server seemed to not be getting its dll’s from the GAC or the local directory but from C:\Documents and Settings\…\Local Settings\Application Data\assembly\dl2\…\…\…\… [actually GWVO70ZL.PCT\NK9B96Q2.MNJ\0da889d1\4c31828b_0a62c501]. So like any careful developer, I deleted the whole tree of files below dl2. Rebuilding the project installs the dll and dependencies into various directories within this tree (the first two parts of the path stayed static).

 

How “Register for Com” seems to work

I will therefore make the several leaps of intuition to come up with the following scenario. When a project is compiled with Register for Com checked then it builds the Dlls as normal and copies it and its dependencies to the output directory (usually bin/Debug). The TLB is also generated and placed in the output directory. Now for the fun bit, each dll is copied into the C:\Documents and Settings\…\Local Settings\Application Data\assembly\dl2\[xxx\xxx]\[yyy\yyy] path where [xxx\xxx] is common to all dlls, but [yyy\yyy] is specific to each. Along with each dll Visual Studio also places the .pdb  and an __AssemblyInfo__.ini file.

e.g.

[AssemblyInfo]

Signature=….

MVID=….

URL=file:///C:/vss/xxx V2.1/xxx.Bank/ExcelRTDOffice11/bin/Debug/xxx.xxx.Data.DLL

DisplayName=xxx.xxx.Data, Version=2.0.0.1, Culture=neutral, PublicKeyToken=e64fdb2f….d84

 

In another [yyy\yyy] a copy of Microsoft.VSDesigner.DLL 7.10.3077.0 is placed, and the whole lot of dlls in \[xxx\xxx]\[yyy\yyy] are registered. Finally the TLB is used to specify the COM part.

 

Recovered Post: Performance Counters

Intro

At work I have a set of server processes that run and process emails. Once processed then an event is set out to our clients informing them that the new data for the primary key is available. Synchronoulsy. This of course has the effect that every client machine has to read from the server to update before the next email can be parsed, and should a client stop responding then the whole process hangs.

So my recent bug fix was to separate the parsing of the emails from the Notification of the clients. I used a Queue wrapped in a Thread Safe manner, and added into a singleton class. The add method then kicks off a thread (should one not already exist) which then starts dispatching the messages out to the clients.

Now what this has do with instrumentation is that the queue needs monitoring so that you can see how far the dispatch of the clients is getting behind the parsing of the emails. Now that is where the Performance Counter classes come in

http://msdn.microsoft.com/…/vbwlkEnumeratingPerformanceCountersOnServerStepByStep.asp or ms-help://…/vbtskcreatingcustomperformancecounters.htm

Things I found

Well I’ve had issues with loosing all Performance counters (yes that includes System counters as well) on two machines.

I also found that it was much easier to work with Instances than without.