Friday, November 7, 2008

That which is old is new again

Last week at PDC, I was able to make it to the repeat session of Anders Hejlsberg's talk on the future of C#.  A talk by Anders is always interesting and enjoyable. He showed some really interesting things; but the most intriguing thing was the new "dynamic" keyword. Anders demonstrated several interesting uses for this "newfangled" gizmo, such as interoperating with JavaScript code. Hmm... I think I demonstrated something just like that over a year ago with Delphi. In that demonstration I showed how you could get JavaScript to access Delphi components dynamically. The reverse could just as easily have been done by using a Variant along with the very old (like Delphi 3 old) notion of dynamic variant dispatching. Any variant can be treated like an object in that you can simply start calling any old method or accessing any old property without even having a declaration for what that property is. For instance for many years you've been able to do this:

procedure TForm1.Button1Click(Sender: TObject);
var
Doc, Word: Variant;
begin
Word := CreateOleObject('Word.Application');
Doc := Word.Documents.Add();
Doc.Content.InsertAfter('This is some sample Text');
Word.ActiveWindow.Visible := True;
end;

Just add ComObj to your uses list and you can now paste that code into a button click, and you're automating MS Word. The Delphi Variant type (or the more COM/OLE specific OleVariant) support this dynamically typed, dynamic invocation.


I had a chance to meet with Anders for a few moments out in the "Big Room" and I mentioned that the whole "dynamic" thing looked remarkably like the old Variant dispatching stuff. He chuckled and mentioned that the C# model allows for doing different kinds of dispatching and not just COM IDispatch... Hmm... I smiled and reminded him that Delphi does as well. I explained that since Delphi initially introduced the Variant dispatching in D3, we've added support for custom variant types. We now support all kinds kind of dynamic dispatching by creating your own custom variant type by descending from TInvokableVariantType over in the Variants unit. He paused a moment, chucked again, and explained that really none of these concepts are new, we're just all learning how to reconcile the strongly-type world with the dynamically typed world of JavaScript, Python, and Ruby. Using the above notion of a TInvokeableVariantType, you could create a custom variant type that allows you to directly call and manipulate... oh... say... some RESTful service. It would be interesting to be able to do this:

procedure TForm1.Button1Click(Sender: TObject);
var
I: Integer;
Twitter, Timeline: Variant;
begin
Twitter := OpenXMLRESTConnection('http://twitter.com/statuses');
Timeline := Twitter.public_timeline();
//for I := VarArrayLowBound(Timeline.statuses, 0) to VarArrayHighBound(Timeline.statuses, 0) do
for I := 0 to Timeline.statuses.count - 1 do // This is far better and easier to use.
begin
Memo1.Lines.Add(Format('User: %s; Message: %s', [Timeline.statuses[I].user.name, Timeline.statuses[I].text]));
Memo1.Lines.Add('');
end;
end;

The above code is purely conjecture on my part, but I can certainly envision such an easy to use, dynamic mechanism to accessing RESTful services.


So, we've appeared to have, yet again, come full circle. That which was old is now new again. Hmm... maybe some of those old codgers back in the 70s, 80s, and 90s were on to something? I just hope we're not merely repeating history, but rather building on it and recognizing that there are only a few new ideas under the sun... knowledge and ideas are not silos unto themselves, but rather built on top of that which has come before. So maybe you could go back even further? Even with the invention of the the first widely used "programable" devices (the programmable fabric loom head) by Jacquard, many of the concepts and ideas of modern computing today can be easily traced back to 1801 and the great pioneers and thinkers of the day.


You can read about the Twitter API here and see how the above code snippet could easily be mapped to it.  To see the XML response just navigate here: http://twitter.com/statuses/public_timeline.xml.

Monday, November 3, 2008

PDC - In a few bullet points

Last week I was at PDC 2008 in Los Angeles. It really felt like a huge BorCon. The "geek quotient" was very high :-). There were several high-level themes that permeated the whole conference:

  • Windows Azure - "The Cloud." Cloud computing with high-level tooling and initial support for managed code. Will eventually support native code. Meh :-/
  • Parallel Computing - "No magic bullet" - As a reminder, Moore's Law is about transistor density not clock speed, folks! Moore's Law is still going strong, only now it is about cramming more cores into the same space. Until the heat/power problem is solved, clock speeds will continue to stall. Now the focus is on doing more things an once. The "free lunch" is over. With the new interest in parallelism and multi-core, classic imperative programming models don't lend themselves to automatic parallelism. In other words, we're a long way from that magic compiler switch called, "make my program parallel and faster." Thus there is a keen interest in data immutability and functional languages (F#, Haskell, ML, Caml, OCaml, etc..) and adding functional programming constructs to existing imperative languages (LINQ, PLINQ). The former is nice for greenfield projects or for portions of an application, but the latter is most likely going to the route taken by the mainstream languages. Consider that the forthcoming C++0x is introducing Lambda expressions, C# has LINQ & PLINQ, and even Delphi is moving in that direction with Prism and Delphi native (LINQ in Prism, anon methods in native).
  • Windows 7 - Pay no attention to the Vista in the corner... Look at Windows 7! Admittedly, it does look nice. They've done a lot of homework and are working very hard to "fix" the usability issues with Vista. The Driver Model is remaining largely unchanged from Vista so all the investment in getting good Vista drivers up an going can be preserved. They seemed to hint that much of the perceived "instabilities" of Vista (aside from the usability issues) were due to the extensive reworking of a lot of the driver model, most notably the Video driver model and DX10. A lot of the hardware vendors were just not ready at launch with solid driver support. Apparently, it's getting better and by the time Win7 is released, the hardware vendors will have ironed out those problems. When will it be released? The statements made were "3 years from the general availability of Vista" which puts it into the last half of 2010. I suspect the move back to a version number from years (98, 2000) or names (XP, Vista) is a way of "starting fresh" and shedding some of the negative baggage that is Vista.
  • Multi-Touch - Windows 7 will support multi-touch out of the box. They also had a whole bunch of Surface PCs. It is interesting to note that the Surface PC is all vision based using a camera placed underneath the rear projected display, while all the Windows 7 APIs are based on the more traditional touch screen technologies (resistive, capacitive, etc...) WPF will eventually have some "unifying" APIs that will map those two APIs to a common WPF layer. This is not until .NET 4.0, which is apparently after Windows 7 since they keep talking about Windows 7 shipping with .NET 3.5 SP1. No word on native Surface APIs. Windows 7 touch support is all native at the lower level and even has some really nice intrinsic support for "manipulators" and "inertia."

Then there was the big Embarcadero/CodeGear announcement of Delphi Prism. Now that we've gone public with information about Prism and Embarcadero's relationship with RemObjects, I can certainly talk about how I was able to spend time with some of the guys from RO. They're booth was setup right next to the Embarcadero booth. I ended up staying the same hotel as the RO guys, so I spent a good amount of time getting to know them better. I met Carlo Kok, the Delphi Prism compiler engineer, for the first time. I certainly enjoyed hanging out with marc hoffman, Mike Oriss, and Carlo Kok. We will be spending a lot of time looking at ways we can not only leverage each other's work, but also work together on advancing the Delphi Object Pascal language in ways that make sense for each market and platform.

Overall, there was a lot of really good information. I didn't come away feeling like there was any kind of overall "buzz" around any particular topic. If I had to pick one "buzz-worthy" item, it would have to be the whole Azure thing and the "cloud."

One personally interesting item was that they gave out a little Freescale USB "badge" sensor board to demonstrate the both the unified sensor API coming in Windows 7, but also the new user level driver model. This little technology demonstrator has a ColdFire V1 microcontroller, which is a MC68000 derivative CPU, with lots of built-in I/O ports, timers, USB port, SCI, I2C, A/D converters and 128K flash Memory and 64K of ram. The board had a 3-axis accelerometer, ambient light sensor, 8 proximity touch switches, Lithium-Ion rechargeable coin cell and charger circuit. It came with all the drivers, on board firmware, trial versions of the C/C++ compiler for the CPU, and the Windows 7 driver code and some demo applications. They said it would only work with Windows 7. Hogwash, I say! It's just a USB HID (Human Interface Device), and well, guess what? Within the extensive JEDI-VCL library is an HID component. There was also enough documentation to describe the 64-byte data packets that the board sends out with information about the accelerometer, light sensor and 8 proximity switches that I was able to write a little Delphi application to read and interpret the raw data stream. Sure, it's using the raw data streams from the device without the nicely unified Sensor API from Windows 7. I played with it over the weekend and got it all working on my Windows XP Dell D820 laptop.