Saturday, September 10, 2005

High Order Messaging

Marcel Weiher sent a mail on the objc mailing-list about a paper he wrote (with Stéphane Ducasse) on High Order Messaging. Basically, HOM is a message that takes another message as a parameter -- like in functional language you have High Order Functions that take a function as parameter.

Ok, nice name .. but why is it interesting ? Well, you have lots of cases where it's really neat :-) but the most known is to use it for iterations. Imagine you have an array containing objects, and you want to send to all of them a message. In Objective-C you'd do:


int i;
for (i=0; i<[myArray count]; i++)
{
id currentElem = [myArray objectAtIndex: i];
[currentElem aMessage];
}

You could also use an enumerator (NSEnumerator) but that doesn't really simplify things. What's the problem with that ? Well, you have code (the for loop..) that you don't really care about, that is actually always the same, you need to deal with each elements, etc. Basically, the programmer's intent is not immediately clear. And of course, the more code you have, the more you can encounteer bugs... So simplifying this pattern would be great. Well, with HOM you will do:

[[myArray do] aMessage];

Better, no ?

Conceptually, the message "do" takes another message as parameter -- it's a HOM. Here it actually bounces the message to all the elements of the array -- therefore, encapsulating the iteration pattern.

Technically, it's a rather cool usage of the Objective-C runtime -- no need to change anything to your compiler :-) -- the HOM message actually returns a Trampoline object that will get the message send to it via forwardInvocation. Read the paper for a good description.

So, using HOM is great for encapsulating the iteration pattern, ok. But after all, we have the makeObjectsPerformSelector.. so why using HOM ?.. Well, the difference is that YOU can create new HOMs, and you are not limited to the iteration pattern :-)

Another good example from the paper.. You have a delegate object you need to send a message to. You'll have the following code:

if ( [delegate respondsToSelector: @selector(windowDidClose:) ]
{
[delegate windowDidClose: self];
}

Again, this is a frequent pattern. Moreover, it's prone to errors -- the selector in the test needs to be equal to the message you send.. An HOM equivalent will be:

[[delegate ifResponds] windowDidClose: self];

Elegant, no ?

Just to finish.. some other examples from the paper:

Starting a method in a thread is done like that in OpenStep:

[NSThread detachNewThreadSelector: @selector(doSomething)
toTarget: receiver withObject: nil];

The HOM equivalent:

[[object async] doSomething];

Or say you want to send a message with a delay.. In OpenStep:

[receiver performSelector: @selector(doSomething)
withObject: nil afterDelay: 1.0];

With HOM:

[[object afterDelay: 1.0] doSomething];


I remember reading about HOM on Marcel's site before this paper, but this paper is an excellent presentation of the idea and do a great job highlighting the possibilities -- another useful mechanism to add to your toolbox to capture patterns :-)

Many HOM implementations exists (in addition to Marcel's original, MPWFoundation), that you can check on that page

Friday, September 02, 2005

PDA, Dynabook and Etoile

I started to think how Etoile could possibly works on -- and take advantage of -- a PDA or Tablet platform...

With the help of Jesse Ross I wrote this page
on the Etoile's wiki; another related page I wrote is one about the Dynabook

Thoughts ?

Monday, August 29, 2005

VERY interesting videos

Following a link from the Squeak-dev mailing list... I watched theses two videos (a presentation in two parts) by Alan Kay, circa 87 ... They are brilliant, and extremely interesting. Definitely something to view !

Part 1

Part 2

(ps: Squeak is an incredible environment, and Seaside is a fantastic web app framework running in Squeak... worth your time..)

addendum: Interesting PDF about PARC's work ...

addendum 2: another interesting video, an interview of alan kay.

Saturday, August 06, 2005

Screenshot UKUUG Demo

Just to show you how the demo was looking:



Nice no ? :)

UKUUG Talk

I just gave the UKUUG gnustep presentation an hour ago, and I think it went fine...
Not completely as planned -- I wanted to use keynote on an ibook for the slides part, and use my powerbook under linux to make the demonstration via a vnc connection, and of course... when I tried the setup yesterday it worked without a hitch. But when I tried today just before the presentation the client didn't want to connect for whatever reason .. as I didn't have the time to find what was the problem, I ended doing the keynote presentation with the powerbook (at least it was faster and smoother than if I had used the ibook g3..), and just rebooted under linux for the demo. Not as smooth, but that was ok.

The GNUstep presentation .. -- well, manipulating apps wasn't that easy as the screen wasn't cloned, so I needed to look to the projection screen instead... ;-) but I was able to present mostly all I wanted:


  • GWorkspace, with Camaelon + the new icons from jasper...

  • panel hiding, applications hiding, tear-off menus (but all rather quickly though... not sure I explained well that part)

  • the services system, taking the LaTeX service, the Zipper service and the GNUMail service as example (LaTeX in Ink.app, then use Zipper to create some tgz from GWorkspace, and finally select the tgz and mail it via GNUMail...

  • GORM -- I started with the basic demo of slider + textview linked together, then I did a demo using a custom palette I wrote yesterday (just for the talk!), which had one object managing a volumetric dataset (a head), and two views rendering the dataset. So it let you create a complete app visualizing a dataset in different way... all in Gorm, without needed to code anything. Pretty nice I thought ;-)



I could have talked much longer than the authorized time, I forgot to say and show some things, but all in all it went well. At the end of the talk the chairman asked how many people had used GNUstep before the talk (3 persons), and how many will try after the talk (5-6 persons?). With around 20+ persons (?) in the room that wasn't bad ;-)

Apparently people were impressed by Gorm :-) , and liked the look of the apps ("it's clean") -- good icons and Camaelon did their job I guess ;-)

I'll put some screenshots later so you could see how did that look..

Wednesday, August 03, 2005

update...

Well, quite a lot of things to do this week... in the end I didn't have time to work on camaelon last weekend (well, I worked on the glyph bug) but camaelon 2 release is still planned soon, along with other étoilé's components (hopefully this weekend ? finally ?) .. I need to fix the display glyph bugs in -gui first..

Else, I'm preparing the GNUstep talk I'm giving at the UKUUG 2005 Linux Technical Conference this saturday at the university of swansea, I'll try to make a cool demo of gorm, showing the power of building apps with components .. ;-)

On other topics.. my bag was stolen this afternoon *on my desk*, in the lab, when I went to lunch for half an hour... quite a few things inside, like, my passport, my keys, my newton... that really, really sucks. damn. This in a building supposedly with secured access..