Saturday, April 17, 2010

.Net 4.0, VS 2010, F#2 etc -- quick reactions

It's a pain that we don't yet have a F# for .net 4 compiler except in non-Express versions of VS2010; the transition from 1.9.9.9 to 2.0.0.0 for .net 3.5sp1 was completely painless for my infrastructure project, but the migration to building under .net 4 will be delayed.

As for my usual toolchain, nUnit 2.5.4.10098 works following the recipe here for tweaking app.config

<configuration>
    <startup>
        <requiredRuntime version="v4.0.30319" />
    </startup>
...
 <runtime>
      <loadFromRemoteSources enabled="true" />
...

with command line flag /framework=net-4.0.30319; FxCop 1.36 with just the requiredRuntime clause added to the app.config.

If you don't set these when trying to analyze .net4 code, you get some pretty obvious runtime version mismatch diagnostics that tell you not to do that again.

And as expected, NCover 1.5.8 (free) loses the plot completely -- it can't connect to the changed profiling API.

I am currently investigating an alternative, which so far hasn't ruled itself out completely when running under .net 4 : it hasn't worked as-is, but I suspect that may be more due to F# than .net 4 (Unhandled Exception: System.ArgumentException: An item with the same key has already been added. in Coverage.Common.PdbReader.GetSegmentsByMethod) -- so I shall have to fork that and bugfix.

Later: This turns out to be in a method that sets up a dictionary of offset to code block (from line,column to to line,column), and is almost certainly a manifestation of the phantom code blocks I've seen before in F# -- which would mean simply having to identify and drop any blocks which are just NOPs.

Thursday, April 15, 2010

More predictable this time

Five years ago to the day I got a very strange result for suggested voting intention.

This time it's right on the money, at least for the top slot; the rest, not so much.

Take the Who Should You Vote For? UK General Election quiz

UK Independence
 
34
Green
 
23
Liberal Democrat
 
18
Conservative
 
10
Labour-44
 

You expected: UKIP

Your recommendation: UK Independence Party

Sunday, April 11, 2010

Anime — ソ•ラ•ノ•ヲ•ト (Sora No Woto, Sound of the skies)

An all original anime series, and the only one from the first quarter of this year I've even felt worth investigating.

It started with the teaser text "In a future land marred by a long lasting war, a quiet decline has begun. 15-year-old Kumika [sic] realises her dream to enlist in the army, and joins a unit of five in protecting a fortress. Together they create music that reverberates across the skies, over empty towns and empty seas." The musical theme plus the character designs caused a lot of people to liken it to cute girls comedy show K-ON!, and suggest synopses like

Episode 1: Kanata enlist in the Military
Episode 2: Kanata gets her first weapon
Episode 3: Kanata fails her army obstacle course and the gang gives 
           special lessons to help her pass.
Episode 4: Summer Vacation outside the fortress
Episode 5: /k/-ON gang lacks an officer in their fortress so they go 
           back to HQ to get one
Episode 6: Army Parade
Episode 7: Christmas at the fortress
Episode 8: Army Recruitment Drive
Episode 9: New moe soldier got recruited into the fortress
Episode 10: Summer Vacation outside the fortress. AGAIN!
Episode 11: Kanata's weapon is rusted, so the gang goes back to HQ to 
            maintain her weapon
Episode 12: Army Parade. AGAIN
Episode 13: Winter break. 

Then a preview came out, showing vaguely Spanish architecture and melancholy music, and it seemed that this was actually going to be more YKK meets Haibane Renmei than K-ON!, and intriguing enough to follow up.

Yes, Kanata Sorami, to whom we are first introduced, seems the usual ditzy anime high-schooler, but we already have some enigmatic back story where as a young girl she met a soldier who played the trumpet, a meeting which inspired her to follow in the same path. And as she walks through the town from where she is dropped off, to the fortress where she is stationed, we are introduced to the legend of the town -- the annual water-sprinkling festival that commemorates when five maidens from the fortress, aided by a giant spider, sacrificed themselves to protect the town from a demon, the legend being told to a background of faux-Klimt art intercut with scenes around the town, the fortress and the surrounding area -- with the mention of the spider flashing to one of the other girls working on a something mechanical that we later learn is a spider tank.

By the next episode it's clear that this is going to be an eclectic series --

Japanese girls wearing German uniforms exploring a Japanese music school in a Spanish town full of French people in Switzerland, shooting South African owls with German rifles -- MAKES PERFECT SENSE.

and, in amongst some "cute girls doing cute things" episodes, slowly some details of this exhausted world are revealed; and always, in the background, the haunting sound of Amazing Grace, played on the trumpet.

Yes, there are a few things that make for double-takes -- they have walking tanks, but only the one fixed-line phone from HQ to the fortress, and signalling from tanks is done by bugle calls and not radio -- but ultimately, this show is more about mood than anything else. That is, up until the last minute where there's a pointless epilog that jars with the quite satisfying conclusion.

In all, a good series, that maybe didn't fulfil all its ambitions, but stood head and shoulders above the rest of the shows that made their début at the start of the year.

Anime — Letter Bee

An offbeat setting, this one : a world in perpetual night, save for an artificial sun; an Edwardian style setting, with occasional anachronisms like the one motorbike shown; D&D style wilderness between each settlement, inhabited by mechanical steam-punk style bugs (gaichuu), and the main traffic between towns are the Letter Bees (equally often referred to as such in English, as well as Tegami Bachi in Japanese. And there's a lot of crazy Engrish in the naming of places (Broccoli Forest, Breath Mint Pass,...).

The story opens with one Bee, Gauche Suede, finding a young boy, Lag Seeing, who has been marked with enough postage to take him to his aunt for fostering -- this serves to introduce us to the setting, the postmen Bees with the magic amber powered guns (the setting collectively being known as Amberground) that enable them to channel their energies into effective attacks against the gaichuu, and their companions, known as dingos; then timeskip and the boy now wants to follow in his rescuer's career.

On the way to his interview, he happens across a girl in similar circumstances to his own who has been abandoned with insufficient postage -- so to prove himself he undertakes the delivery, only to find she's being sent to a freak show; outcome, the half-monster girl he's named Niche (after where he found her) becomes his dingo.

With Lag, we find out more about this world; and we regularly get sentimental tales about the feelings bound into letters -- the whole series is really a paean to the old-fashioned snail-mail correspondence of yore -- especially as Lag's magical energies are just designed to evoke these sorts of echoes from anything they strike.

And there's a long running thread behind all of this about what happened to Gauche after he just went missing some point during the timeskip, the presence of rebels against the settled order of things, and what was going on when the artificial Sun went out for a few minutes the day Lag was born, and a government airship came crashing down? There's a second season planned, so no doubt we'll find out then.

Unusually, the secondary characters include a wheelchair-bound girl, Suzette, who is Gauche's younger sister and shares birth date with Lag. The question of how she navigates doorsteps as tall as the radius of her main wheels is finessed -- in fact there's a distinct lack of adaptations in her house.

One thing that struck me about this series was the background music -- not just Sub-Postmistress Aria playing Air on a G string (lower right); but all though, there was a good string-based orchestral sound track. OP and ED were J-pop, with, to my mind, the first pair better than the ones that took over half way through.


Anime — Miracle Train : Welcome to the Oedo Line

Japan's love of anthropomorphization strikes again -- at the start of 2009 it was soft drink cans, this time it's train stations, in a man-service anime for girls.

I picked this one up as something for Karen to counter the girl-heavy bias of the normal selection of shows, but quite enjoyed it. It is slight -- most of the episodes are of the form "Girl boards train; girl discovers it's occupied by half a dozen suave young men in uniform; girl freaks a bit, but eventually is coaxed into telling about her problems; the guys then let her talk the problem out, with a little bit of slapstick and sight-seeing in their vicinity; everyone happy." -- but never gets embarrassingly bad or stupid. The worst it gets are in the three episodes outside the usual problem-solving where it tries for a bit of profundity while doing the "Secret Origins of the Miracle Train" and never quite seems sure of the mood or genre it's aiming for. And along the way you'll learn more trainspotter trivia for one of the newer lines in the Tokyo underground.

Overall -- Surprisingly good for Japanese light comedy.

Monday, March 29, 2010

Out like a lion...

For the last week it has been mild, and often dry -- so that the daffodils and forsythia have all suddenly burst into bloom; and the weeds are going mad in the garden. But the forecast is for colder, wet and much windier weather running up to Easter.

I took the day off today to use up some carry-over leave, and to take the new wheelchair-accessible car for a spin to take Karen out to lunch; but not a long run -- so went to the Golden Ball at Boxworth, one of the usual pub-lunch haunts from work. I'm sure the process of doing all the belts, buckles, brakes, gears, etc. will get smoother with practise. And I got a bit of unexpected manoeuvring practise when heading to Knapwell, finding the road blocked with a police car and an ambulance, so having to make a 3-point turn in a very narrow lane. Still, that was all gone on the way back, and we could enjoy the vast display of daffs along the verges through the village.

Although a frequent from-work place, I'd expected that Monday would avoid the risk of running into colleagues. So imagine my surprise when the first faces I spotted as I walked through the door were they! Still, we didn't have to rush off quickly to get back for meetings at 2pm.

Restoring CompressedFolder opening for zip files

Having gotten to the point of being annoyed by the way that WinZip overwrote the association, I finally crawled around the web to find a way to restore the CompressedFolder functionality as a more convenient method for reading, even if I want finer control for writing.

Most places talking about this are mildly dodgy, want to have you drop massive slabs of stuff into your registry or say "re-install your OS". Fortunately it's easier than that.

Run regedit, and go to HKEY_CLASSES_ROOT\.zip and change the (Default) value to CompressedFolder. That restores Explore as the default option, which was what I was after.

Sunday, March 28, 2010

How-To : IronPython and callback delegates with 'out' or 'ref' parameters

Following up on the earlier post, having found time to engage the brain a little...

Let's do the int flavoured version, everything non-default:

and then in IronPython ask the variable about itself

Now we get

>"\Program Files\IronPython 2.6\ipy.exe" callback.py
<type 'StrongBox[int]'>
['Equals', 'GetHashCode', 'GetType', 'MemberwiseClone', 'ReferenceEquals', 'ToSt
ring', 'Value', '__class__', '__delattr__', '__doc__', '__format__', '__getattri
bute__', '__hash__', '__init__', '__new__', '__reduce__', '__reduce_ex__', '__re
pr__', '__setattr__', '__str__', '__subclasshook__']
Array[object]((<System.IntPtr object at 0x000000000000002B [42]>, 17))

That Value member looks interesting, so...

which gives us

>"\Program Files\IronPython 2.6\ipy.exe" callback.py
Array[object]((<System.IntPtr object at 0x000000000000002B [42]>, 23))

which is what we were looking for.

Rebuilding the C# assembly with out rather than ref and re-instating the print lines shows that the argument is still passed as a StrongBox, so there is no change on the IronPython side.

Armed with this piece of knowledge about the type, I tried Googling again, and didn't find any obvious mentions of callbacks -- just the converse matter of calling .Net methods that take out or ref parameters. But that at least is enough to reassure me that this is not just some completely undocumented hack that would be subject to change in later versions.

Note also that if I had written

print x.GetType().ToString()

(which is what I did the first time around) rather than

print type(x)

I would have gotten the result System.Int32, which gives no clue that adding

print dir(x)

is at all something worth doing.

Sunday, March 21, 2010

Spring

Cycled to work again on Friday -- and then a high-speed blitz into town for a short notice appointment early afternoon. So, the tooth with a cracked filling that had been playing me up for the last few weeks is now patched until the proper fix in May.

And next week is looking plausible for more cycling.

Mowed the lawn, what there is that isn't moss, and did some spring pruning, enough to fill up the green bin, before settling. And potted up some chilli seedlings and put them into a heated propagator in the greenhouse.

Thursday, March 18, 2010

Milestones

Only 35,932 this year or 5228 miles. Now some of that will be due to not having gone to the gym over the winter because of other commitments and some due to being snowed in a lot more or otherwise working from home. And probably rather more cycling

Tuesday, March 16, 2010

Spring

Suddenly a spell of mild dry weather -- Saturday, cycling into town for the first time in some weeks, and to the garden centre to pick up some supplies; and having my other gear cable snap while on off-road bridleway. So a bit of pushing as being stuck in top was not suited to the terrain.

Fumigated the greenhouse overnight, and then did bicycle repair -- much easier the second time around -- and put everything back on Sunday. That was warm enough to work up a bit of a sweat -- but in the greenhouse is cheating.

And today, cycled to work for the first time since mid-October; then had that first real day of T-shirt weather -- although a lot of people were still muffled up. Mild enough this evening that the central heating suddenly went from just keeping the chill off to being rather too much!

Sunday, March 07, 2010

IronPython, WPF, and button-free windows

So, how do we achieve something like this with WPF, using IronPython?

Assume Vista or later (if you want to support XP, do something different if System.Environment.OSVersion.Version.Major < 6)

Start with some XAML

<Window
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window2" Height="300" Width="400" MinWidth="400" MinHeight="100"  WindowStyle="None" AllowsTransparency="True">
    <Grid>
        <Grid Name="banner">
            <Image Name="icon" Stretch="Fill" HorizontalAlignment="Left" VerticalAlignment="Top" Width="20" Height="20" Margin="4,4,0,0" />
            <Label Height="28" Name="title" VerticalAlignment="Top" Background="WhiteSmoke" Margin="28,0,0,0">Label</Label>
        </Grid>
        <StackPanel Margin="0,28,0,0" Name="body" VerticalAlignment="Top" Height="230">
            <TextBlock Height="100" Name="message" VerticalAlignment="Top" />
            <Image Name="image" Stretch="None" Height="130" Width="400" />
        </StackPanel>
        <StackPanel Name="buttons" Height="55" VerticalAlignment="Bottom" Orientation="Horizontal">
            <!-- Button Height="23" Name="button1" Width="75" Margin="2">Button</Button -->
        </StackPanel>
    </Grid>
</Window>

We can then use ctypes to get at the glass APIs, and set up some re-usable types

which we can then hook into our window (assume we have loaded the XAML into a variable window)

Of course you now need to ensure you have some button or other control that will let you dismiss the window, now you no longer have the kiss of death available at top right.

The ref parameter in the WndProc hook is the reason behind the previous post...

IronPython and callback delegates with 'out' or 'ref' parameters -- the obvious way doesn't work

The actual how-to is given here.

The only on-line documentation I could find that mentioned this has a

TODO - Delegates with out/ref parameters

about halfway down.

So, experiment time. Build callback.dll containing (or the same with 'out'):

and call it from IronPython 2.6:

which yields

Array[object]((<System.IntPtr object at 0x000000000000002B [42]>, False))

In sum -- it fails silently; the direct return value is fine, but mutating the actually by-value parameter does nothing.

Replacing the bool with int, and using non-default values shows that the value of a ref parameter is passed in correctly, it just can't be passed out with direct assignment.