Friday, May 12, 2006

Intro to WinFX

Jenny and I attended a MS event about WinFX on the 12th. Hopefully, this post will serve as a mini intro for anyone else interested in Microsoft's upcoming technologies.

WinFX is basically MS's new API for windows. It can be accessed via .Net 2.0 code and will come bundled as part of the next OS, Vista, as well as being available to install on WinXP and Server 2003.

There are 3 pillars of WinFX that all follow the somewhat famous architecture outlined by Jack Greenfield in his article, "Software Factories." Greenfield was formerly a bigwig at Rational, where everything had UML as it's foundation and was supposed to be the shiznit, but fizzled. Now his new ideas of using useful models to build real software (though there's more to the article) are becoming a reality. So the model is the code - just as you can design a form in our current tools and it is the actual form you run, so you can create models in a designer and it is the actual logic.

Another main point about the new paradigm of development is that imperative and declaritive code can be separated much more easily. So all the details of what you want to do (connect to this data store, use this protocol, make the interface look like this) are very easily separated from how (business logic). All the declarative code goes into markup (XML or XaML).

So the 3 pillars are:
  • Windows Presentation Foundation - The all new UI.
  • Windows Communication Foundation - Web Services (or services that may reside on the same machine) enabling a service oriented architecture at any level.
  • Windows Workflow Foundation - Modeling as described above.
Presentation Foundation (formerly Avalon)
The UI uses "XaML" to represent any damn thing you can imagine. The graphics engine supports regular bitmaps and vector graphics. There is a pure UI designer piece called "Expression" whose graphics manipulation capabilities I can't adequately describe. With XaML you can describe how you'd like a graphic to rotate, zoom (and vector graphics are crystal clear at any zoom factor), or whatever. The controls you create that display all these graphics can reference templates for consistency. Then the XaML is transferred to the developer. Here's a video of a real application utilizing the presentation foundation. One presenter mentioned that you will be able to run the same XaML on the desktop as is the browser, but this didn't seem to add up as there was a different Expression tool for web pages...

Communication Foundation (Formerly Indigo)
Connect to anything using any transport mechanism with the same type of interface. In a sample app, the presenter had connected to web services, but had also wrapped up communication with a regular human interfaced web page (querying availability of a product on a retailer's web site) for use in the same fashion. So you communicate with another WinFX local service the same way as a web service.

Workflow Foundation (Formerly I don't know what)
There used to be another piece to the WinFX pie called "WinFS," the "FS" for file system, I presume. This piece dealt with an entirely new way to manage files. Files had extensions (not in the name) that allowed for sophisticated organization and retrieval. I'm not sure how much of that stayed in WinFX; as far as I can tell workflow foundation only deals with what I discussed above about being able to visually design your application's logic.
You drop activities down on a design canvas and wire them together as a sequential diagram, a state machine (basically event driven), or as a rules driven machine. You can even simply set a breakpoint on your activities and then step into them if they have additional code behind them. I think this will really encourage code re-use and third party vendors are already making lots of useful "activities". So one of the out-of-box ones (I think) would be send an email message. Drop down that activity, set some of it's properties and let 'er rip. Activities can contain other activities, so you could even have a main activity be one that is the main gateway to persistence (save to data store). Then each time execution enters that activity, it may flow into different sub-activities. Another cool activity example is Amazon's purchase item activity.

Tuesday, May 09, 2006

Refactoring to eliminate duplication

As with a previous post, this may be obvious, but I think merits elucidation and discussion.
There are many cases where some code cries out, "refactor me!", but there never seems to be sufficient time. In the opinion of most leaders in the software community, however, we should make time; our efforts will always pay off.

So here's something commonly seen:

case PartyAnimal.Age of
 2..12:
 begin
  PutRightLegIn;
  PutRightLegOut;
  DoHokeyPokey;
  ShakeAbout;
 end;
 13..19:
 begin
  PutRightLegIn;
  PutRightLegOut;
  DoMacarena;
  ShakeAbout;
 end;
 20..25: //etcetera

We have some obvious repetition here that should be extracted into a method (wouldn't it be really cool if we had an IDE that would do this for us? It does, you say? Please teach me how; BDS gives me an error every time; VS2005 never did).

To emphasize why it should be extracted into a method:
  • When (note - not if) PutRightLegIn needs to change in every case, the change can be made in one place.
  • It makes for less code in the listing (and in the .exe). Less code to do the same thing is always a good thing. (1)
  • To quote Martin Fowler, "the essence of good design is ensuring that the code says everything once and only once." And better design makes for more efficient maintenance. (2)
  • It follows the DRY principle: Every piece of knowledge in the development of something should have a single representation. (3) The piece of knowledge in this case is RightLegIn, RightLegOut, X, ShakeAbout.

So, of course, our refactored case statement (after adding our new method, DoPartyDanceWith) looks like:

case PartyAnimal.Age of
 2..12:  DoPartyDanceWith( HokeyPokey );
 13..19: DoPartyDanceWith( Macarena );
 20..25: //etcetera


I'm hoping the next time each of us has to modify something that looks like this, there will be a greater itch to refactor, then modify.

Notes:
1) The Art of Unix Programming (and a zillion other places)
2) Refactoring
3) The Pragmatic Programmer (and many other places)

Wednesday, May 03, 2006

get_ and set_

By default, if you have a property named MyProp, Delphi assumes methods named GetMyProp and SetMyProp. Per a Delphi 2005 book I have read, Delphi.NET actually compiles this code creating new methods get_MyProp and set_MyProp which in turn call the original methods. We could eliminate this extra layer if we just use get_ and set_ for the original names. This would have at least a minor improvement in performance. So, should we set a standard of get_ and set_ for future property specifier names?

PS: if the specifiers simply refer to an element such as FMyProp, Delphi still creates get_ and set_methods that then access FMyProp.

Read only class attribute

Say I have a class that has some attribute that is basically read only. Each child of the class has a fixed value for this attribute for all instances of that child class. Three possible ways to implement this are:

1. Add an element named MyAttribute. In the constructor, set the value of MyAttribute.

2. Add a function named MyAttribute that is overwritten in each child class.

3. Add an element named FMyAttribute and then add a MyField property with a read specifier of FMyField. In the constructor, set the value of FMyAttribute.

4. Add a Get method named GetMyAttribute and then add a MyField property with a read specifier of GetMyField. In each class, override GetMyAttribute.

I assume option 1 is the least desirable since it doesn't enforce read-only and basically does not fit in with the standards we are striving for. Option 4 is seems to be the most robust, but is overkill. Any opinions.

Tuesday, May 02, 2006

GAIM: Lotus SameTime client replacement

When ING blocked the external IM ports I for one found the Lotus client lacking in features compared to the clients that we had been using. Well the other day on my Mac I noticed that the client I was using had an option for SameTime. This made me ask why we couldn't use a different client at work as well. So I did some looking and found several clients that said they had SameTime support. The client I had previously been using, Trillian, did mention SameTime support but only in their "Pro" version. Another client that said they support SameTime was GAIM. I have been using this client on my Linux box at home for a few years now and have been happy with it. It is free, open source software. There is a Windows port of this program and the rest of this post details my experience so far with it.

If you want to try GAIM for SameTime you first need to download the client using the link at the top of this page. Once downloaded go ahead and install the program. I used the default install options.

Next you will need the GAIM plugin for the SameTime protocol. This plugin is Meanwhile. It can be downloaded from this page. (Updated) Be sure to pick the Windows version. It should be the file with "win" in the name. Once downloaded you can run the install. It should place the plugin into the appropriate folder.

Next open GAIM. It will present you with a login dialog and most likely open the Accounts window. I believe you need to go into Tools->Preferences and select the Meanwhile plugin in the plugins section before adding an account. Forgive me but I don't remember the exact steps for this but I believe it was intuitive.

Once the plugin is active you should be able to use the accounts dialog to add a new account. Select Meanwhile in the type dropdown list. Enter your username and password. Your password should be the same one used for logging into Exchange. For the servername I cut and pasted out of the Lotus client settings. Here's a screenshot of my account settings.

You should now be ready to connect and start IM'ing. For me my buddy list appeared the second I successfully connected. Since it is stored on the server you can make changes here or in the Lotus client and both see the changes. The only area that I've had trouble figuring out in GAIM is adding new buddies. To do this I switch to the Lotus client, add the buddy, then go back to using GAIM.

From here you can go in and customize your settings in Tools->Preferences. I've turned on several of the plugins to improve the behavior as well as logging, conversation history, etc. Here's a screenshot of my pimped out IM client.


I've been using this client for a couple days now with no noticable problems. If all else fails we have the Lotus client to fall back on. Happy IM'ing!