body {margin:0; padding:0; background:#fff; color:#000}td,body,.form {font-family:Tahoma; letter-spacing:1.1lm;font-size: 9pt}A {color:#336699; text-decoration: none;}Anonymous methods are generating a lot of buzz in the Delphi community right now, being one of the bigger changes heading our way in the forthcoming Tiburon (Delphi 2009), along with Unicode and Generics.Unlike Unicode and Generics however, the usefulness of anonymous methods is not nearly as clear.On Joel On SoftwareJoel On Software has been invoked as an authority. Unfortunately, as Joel himself has previously admitted, he does not actually use Delphi, and a great deal of the usefulness he sees in anonymous methods seems to stem from this fact, in that what he describes as the principal benefits of anonymous methods has always been achievable in Delphi.To paraphrase his material on this point: procedure Cook(const aIngredient1, aIngredient2: String; const aCookingMethod: TCookingMethod); begin Alert('get the ' + aIngredient); aCookingMethod(aIngredient1); aCookingMethod(aIngredient2); end;Cook( 'lobster', 'water', PutInPot );Cook( 'chicken', 'coconut', BoomBoom );Joel asks: Can your language do this?If the language is Delphi, yes. We don’t need anonymous methods for this.But that is not the only use for anonymous methods espoused by Joel. He goes on to talk briefly about threading, before seeming to me to go off at something of a tangent to talk about MapReduce, where the applicability of anonymous methods is a little hard to fathom (in the context of languages that “can do this”) and I’m certain that the actual Google MapReduce implementation is a great deal more complex than Joel’s summary, but I’m not so sure that anonymous methods were critical to it’s success, rather than just happening to be a part of it.One wonders if they would have featured at all if Google had used Delphi. Anonymous Methods and ThreadingIn a different blog, Lars Fosdal also mentions threading.Coming at the subject with the Delphi perspective that Joel does not have, Lars aligns the benefits of anonymous methods against the failings of TThread. Not unreasonable, given that TThread is the “out of the box” approach to threading in Delphi and it undeniably has a number of shortcomings. But TThread is not the only game in town for Delphi developers. I myself have needed a more lightweight approach to threading in the past. So I made one. I called it TMotile (a work by Peter F Hamilton brought the term motile to my attention, and the fit was obvious in my mind).My TMotile class can be used in two ways. First to execute some procedure in a fire-and-forget background thread: procedure SomeProcedure; begin // ... end;TMotile.Execute( SomeProcedure );Or secondly in a way perhaps more familiar to those already used to TThread: TMyMotile = class( TMotile ) protected procedure Execute; override; end; procedure TMyMotile.Execute; begin // ... end;TMyMotile.Create;With anonymous methods that fire-and-forget usage could be made simpler:TMotile.Execute( procedure begin // ... end; );Of course, that “simpler” observation is, I think, debatable. If it is “simpler” at all, then actually it isn’t by very much, and arguably it introduces an unacceptable level of noise into the code. This doesn’t appear to be the case when viewed in isolation, but in the context of a