Tuesday, June 26, 2007

scottberkun.com » Blog Archive » Asshole driven development

Nowadays with all kinds of development methodologies, it's refreshing to revisit some real-world ones (in a slightly cynical manner..) 

scottberkun.com » Blog Archive » Asshole driven development

Wednesday, June 20, 2007

Playing around with Powershell

For those living under a rock the newish command shell from Microsoft called Powershell (aka 'Monad') is quite nice.

Get Powershell

It treats everything as object that you can pipe around and you play around with file system, registry, wmi, .net objects, com objects, custom stuff all in the same way.

Let's say you want to play around with WMI and look at your computer.

PS C:\Users\Simon> Get-WmiObject Win32_ComputerSystem

Domain              : WORKGROUP
Manufacturer        : System manufacturer
Model               : System name
Name                : REBORN
PrimaryOwnerName    : Simon
TotalPhysicalMemory : 1609498624

or let's say that you want to find the description of the 3 processes that currently uses the most CPU:

PS C:\Users\Simon> Get-Process |
>> sort-object -property CPU -descending |
>> select-object -first 3 -property Description

Windows Media Player
Desktop Window Manager

Or if you for some reason feel the need to show a messagebox (and yes, the messagebox did show and I hit yes):

PS C:\> [void][System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
PS C:\> [Windows.Forms.MessageBox]::Show("Hello World")

Extension methods and Collection<T>

Visual Studio Code Analysis / FxCop says in rule CA1002 not to expose List<T> but instead something like Collection<T>.

Now List<T> has some nice features such as

List<T> List<T>.FindAll(Predicate<T> match) 

among others, not to mention

void List<T>.AddRange(IEnumerable<T> collection)

Now, we could go implementing these on our own base class and return that, or go back to C style object orientation and write a static CollectionUtilities class with methods such as

static void AddRange<T>(ICollection<T> collection, IEnumerable<T> items)

Neither of these makes me really happy.

Enter C# 3.0 extension methods:

public static void AddRange<T>(this ICollection<T> collection, IEnumerable<T> items)

{ /* implementation */ }

Now due to some compiler magic we can use this method just as it had beed implemented directly in Collection<T>... Neat!

Another interesting tidbit is that it is in fact possible to do things like

            Thing foo = null;
if (foo.IsNull())
Console.WriteLine("foo is null!");

and NOT get a NullReferenceException due to an extension method along the lines of:

        public static bool IsNull(this object value)
return value == null;

unfortunately, as they are called extension methods it's only possible for methods and not properties and such.

Wednesday, June 13, 2007

Microsoft embedding nerdy photo in Vista DVDs? - Engadget

 It seems some guys at Microsoft thought it would be cool to get their pictures on the Vista DVDs, and they seem to have gotten away with it!

Well, obviously I don't know what their managers thought of their ploy...

Microsoft embedding nerdy photo in Vista DVDs? - Engadget

Thursday, June 07, 2007

XAML as a better C#

That was the title of Chris Anderson's talk today. Very different, and very interesting. He explained how CLR and XML fits together in XAML and as a demonstration implemented a "poor-man's Workflow Foundation".

The talk also had it's fair share of humorous moments, when the his computer had a mind of its own.

Conclusion was that although XAML is very powerful, it's not necessarily the best tool for all jobs.

Tuesday, June 05, 2007

TechEd, day 1

Surprisingly, our bags *did* arrive during the night, so we got our clothes, that's nice!

First impression, this event is HUGE.

The keynote was more directed towards IT professionals, so not much interesting stuff to get there.

Orcas seems to have gotten its official name Visual Studio 2008, but release date should still be the end of this year.

You'll get as much SWAG as you want...

Saturday, June 02, 2007

Going to Orlando/TechEd

The bags are packed, hopefully I didn't forget anything too important.

Tomorrow we fly from Turku to Orlando via Copenhagen and Chicago. If everything goes according to plans, we'll land 10.47 PM in Orlando. (With 7 hours of time difference that is if it was 05.47 back home...)

It's gonna be a loong day...

On monday TechEd starts!