Monday, 7 December 2009

is, then as (C#)


The C# language has a pair of related operators, is and as. Say you have an object, x, and you want to know if its really type Form underneath.

(x is Form) will be true if it is, or false if it isn't. The as operator will actually perform the conversion, returning null if it can't be converted to that type.

One common piece of advice to C# programmers is to avoid using the is operator. Here's how both of these operators are typically used together.
    if (x is Form)
    {
        Form frm = x as Form;
        /* Use frm. */
    }

While the code works, all the is operator is doing is performing an as operation, and checking if the result is null or not. In other words, (x is Form) is equivalent to (x as Form != null). This means the code above is really saying...

Sunday, 29 November 2009

Computers are fast!


Killer Sudoku is a popular variant on the perennial Sudoku game found in British newspapers. The same rules about the numbers 1 to 9 appearing only once in row, column and 3x3 box still apply, but unlike Sudoku, the puzzle doesn't come with any numbers filled in. Instead, cells are groups with dotted lines and the total of all those cells are written in.

Here's part of a puzzle. The two cells grouped by a 10 could be 1+9, 2+8, 3+7 or 4+6. (It can't be 5+5 because that would mean two 5s in same box.) Not a lot to work on, but also look at the three cells grouped by a 23 in the same 3x3 box; The only possible fit is 6+8+9. This means the only possible fit for the 10 group is 3+7, as all the possibilities would clash with the 6,8 or 9 required to make the 23.

I could go on. If you want to complete the puzzle, its the Guardian's puzzle number 166. The point of this article isn't to solve the puzzle, but something I observed along the way.

Thursday, 12 November 2009

About This Blog




Jawohl! I am Wilhelm von Hackensplat, software developer and evil genius. This is my blog.

I'll be writing on software development, otherwise known as that-which-pays-the-bills. I've been doing this for most of my life, ever since mother Hackensplat bought a Sinclair ZX81 all those years ago.

I have tried blogging before, but I found myself really dissatisfied with the structure of a blog, specifically the normal view of showing the most recent posts first. To me, that's not the most important thing. I want a casual visitor to bask in my unaccountable brilliance and see my best stuff.