Amazon.com Widgets

Slides and Demos from BorCon

Last week I had a good time at BorCon giving the CLR 2.0 pitch.  As promised here are my slides and demos.  Overall I thought the presentation when well.. I didn’t have any demo’s crash on me!   One of my favorite parts of the presentation was getting to show possible example syntax from a future version of Delphi… I love seeing how languages grow and change.

 

// ** hypothetical syntax from Danny Thorpe **

type

   List<T> = class

   private

      elements: array of T;

      FCount: Integer;

   public

      function getItems(index: Integer): T;

      procedure setItems(index: Integer; value: T);

      procedure Add(element: T);

      property Items[index: Integer]: T read getItems write setItems default;

      property Count: Integer read FCount;

   end;

procedure List<T>.Add(element: T);

begin

   if (FCount = elements.Length) then

      SetLength(elements, FCount * 2);

   elements[FCount] := element;

   Inc(FCount);

end;

function List<T>.getItems(index: Integer): T;

begin

  result := elements[index];

end;

procedure List<T>.setItems(index: Integer; value: T);

begin

  elements[index] := value;

end;

 

 

var

  intList: List<Integer>;

  i: Integer;

begin

  intList := List<Integer>.Create;

intList.Add(1);          // No boxing

intList.Add(2);          // No boxing

intList.Add(‘3’);        // Compile-time error

  i := intList[0];       // No cast required

end;

 

 

I’d love to hear feedback from folks that were at the event… what would you like to see covered differently.  Danny warned me that you’d likely pick apart subtle differences between the way Microsoft talks about the CLR and the way Borland talks about it… I’d love to hear those observations. 

 

 

 

Published 23 September 04 07:29 by BradA
Filed under:

Comments

# Panos Theofanopoulos said on September 23, 2004 8:06 AM:
if elements is null then elements.Length does not throw an exception ?
# Chuck Jazdzewski said on September 23, 2004 9:28 AM:
Even if it didn't you would crash on the very next line because 0 * 2 is still 0.

This code should read,

// ** hypothetical syntax from Danny Thorpe **

type
List<T> = class
private
FEements: array of T;
FCount: Integer;
function GetItems(index: Integer): T;
procedure SetItems(index: Integer; value: T);
public
procedure Add(element: T);
property Items[index: Integer]: T read GetItems write SetItems default;
property Count: Integer read FCount;
end;

procedure List<T>.Add(element: T);
begin
if not Assigned(FElements) then
SetLength(FElements, 4)
else if FElements.Length = FCount then
SetLength(FEements, FCount * 2);
FElements[FCount] := element;
Inc(FCount);
end;

function List<T>.GetItems(index: Integer): T;
begin
Result := FElements[index];
end;

procedure List<T>.SetItems(index: Integer; value: T);
begin
FElements[index] := value;
end;

var
intList: List<Integer>;
i: Integer;

begin
intList := List<Integer>.Create;
intList.Add(1); // No boxing
intList.Add(2); // No boxing
intList.Add(‘3’); // Compile-time error
i := intList[0]; // No cast required
end.
# Staffan Malmgrens blogg » Blog Archive » Quickies of the day said on October 24, 2006 4:17 AM:

PingBack from http://externblog.tomtebo.org/2004/09/24/quickies_of_the_day-2

New Comments to this post are disabled

Search

This Blog

Syndication

Page view tracker