I really old (71 next month), do not depend on Delphi for making a living, mired in Delphi 6 approaches to coding, and needing some motivation to move into the D2010-XE3 era. I'd like to start with Generics and Anonymous Methods (G&AM) and leave extended RTTI aside for this post:

I really old (71 next month), do not depend on Delphi for making a living, mired in Delphi 6 approaches to coding, and needing some motivation to move into the D2010-XE3 era. I'd like to start with Generics and Anonymous Methods (G&AM) and leave extended RTTI aside for this post:

1. What can I do with G&AM that would be impossible in D6?
2. Is G&AM code easier to write or understand?
3. Is G&AM faster or more economical memory-wise?
4. What are some coding tasks for which I should definitely be using G&AM?

Comments

  1. Dorin Duminica - Simply by looking at the size of the code base (KLOC) before and after the Generics refactoring.  The uncertainty is due to other code being added (or removed) during the same period.

    It can very well be more than that.  The more boiler plate classes you have, the bigger the reduction.

    ReplyDelete
  2. While Lars showed quite an advanced use of G&AM, IMO one of the most simple but powerful uses of Generics is the TList case: While in D6 you only had a TList holding pointers, and as such those pointers pointed to e.g. class instances requiring  a (potentially unsave) cast to a class type a lá TmyObject(TList[i]).WhateverFunction, in the world of Generics you can now declare a list like this:
    TmyObjectList = TList;

    and then safely access list entries by

    MyList[i].WhatEverFunction;

    About execution speed and memory:
    While I don't think that execution is faster, memory footprint is definitely higher with Generics, as each concrete type of a generic type creates its own class. So, TList and Tlist creates two distinct classes. In most cases however I think this increase in memory usage should be of no concern.

    ReplyDelete

Post a Comment