Archive for October 2009

How to leak a class you never defined

Quick, what’s wrong with this code?

[code lang="delphi"]
procedure ContrivedExample;
var
   factorial: TFunc;
begin
   factorial :=
      function(input: Integer): integer
      begin
         if (input = 0) or (input = 1) then
            result := input
         else result := input * (factorial(input - 1));
      end;

   writeln(factorial(5));
end;
[/code]

Continue reading ‘How to leak a class you never defined’ »

Real-world optimization

Last week at work, I was asked to look at one of our verification modules that was taking about three times longer to run than it had in an earlier version.  This module takes a set of result files, compares them against another file showing expected results, and reports any discrepancies that are outside the defined margin of error.  It’s some pretty heavy work involving hundreds of thousands of data points, and the old version already took more than ten minutes.  Increasing the running time by a factor of three just wasn’t acceptable.  So I started to look at what was going on.

Continue reading ‘Real-world optimization’ »

Under the hood of an anonymous method

I woke up this morning and checked DelphiFeeds, and found a very interesting post by Jolyon Smith about the use of the absolute keyword.  That reminded me that I had to go and write up this article.  Why?  Because it’s the only way I know of to get inside an anonymous method’s functor object and do some looking around.

Continue reading ‘Under the hood of an anonymous method’ »

Asking the impossible

On TVTropes, one of my favorite websites, there’s a phrase that’s only invoked when an author writes about something real, but uses it in a way that’s impossible and completely contrary to its nature: “X does not work that way.”  For example, if a sci-fi show features space fighters dogfighting and making turns that would only be possible with atmospheric friction against the hull, or gradually drifting to a stop if the engines stop thrusting, that might get listed under “Space does not work that way.”

What does this have to do with Delphi programming?  Bear with me.  Continue reading ‘Asking the impossible’ »