Board index » delphi » Re: Generics + D2007/win32

Re: Generics + D2007/win32


2006-06-02 05:56:28 AM
delphi0
Quote
So I get strongly type-safe lists *and* no need for typecasting. Without
generics I'd either have to create a TPersonList class, or I would
have to use TList and run the risk of adding a non-person to the list (bug
not found until runtime) and I'd have to do lots of typecasting.

Do you not like using TCollection and TCollectionItem? I still get strong
typecasting with those two methods with very little extra code and I've
found that I *prefer* that over Generics for the very reason of extension.
My TCollection class is all primed for easily adding a new method.
Using your Person list example, if I was required to know how many people in
my list that had a valid address, it is just a new public function on the
TPersonCollection class. In the generics world, it is not as easy to
encapsulate that into the List<Person>class...
-BKN
 
 

Re: Generics + D2007/win32

Jim Cooper writes:
Quote
So you're not a fan of agile methodologies then? :-)
Honestly, I am not sure!
Quote
That sounds like the waterfall model
Until you start iteration no 2
Quote
in the real world.
I am talking about what the theory says :-)
Quote
There is no reason not to think at any stage of
the process, but focussing on "big design upfront" as some people
call it, is not applicable to all situations. Even in that situation,
you need to be prepared to be flexible, either because requirements
change, or you stuff up :-)
Yes. I was more talking about situations where coding starts on day 1.
Prototyping is fine. And _ i was talking about what my experience is.
--
Ingvar Nilsen
www.ingvarius.com
 

Re: Generics + D2007/win32

Quote
FWIW, the term is an old one in this context. Ada certainly used the term
this way.

Of which Pascal is based on IIRC...
-BKN
 

Re: Generics + D2007/win32

Bryce K. Nielsen writes:
Quote
Do you not like using TCollection and TCollectionItem? I still get
strong typecasting with those two methods with very little extra code
and I have found that I prefer that over Generics for the very reason
of extension.
Very interesting point!
--
Ingvar Nilsen
www.ingvarius.com
 

Re: Generics + D2007/win32

Peter Morris [Droopy eyes software] writes:
Quote
I use generics in dotnet 2 all of the time and now can not think how I
got along without them :-)
This is probably the issue that has most tied me to the C++ ghetto for
the last decade ;?)
Once you get used to a language that supports genericity, it is
exceptionally hard to work in any other way - at least if you want
compiler enforced type-safety.
There does seem to be something of a synergy between strongly typed
languages with generic support, and dynamicly typed languages like
Python and Ruby. The latter are often more productive over the short
term, the former give greater confidence in the integrity of complex
systems where compiler will catch your mis-uses rather than your users!
But both environments require a somewhat more free-wheeling approach to
data-types, allowing you to focus on real software problems rather than
jumping through langauge-shaped hoops.
--
AlisdairM(TeamB)
 

Re: Generics + D2007/win32

Quote
qc.borland.com/wc/qcmain.aspx

Then you will understand the beauty of Generics.

I understand how Generics work and use them in C# quite often now, but I
just get why it seems like there's this huge clamour for them. Sure they're
kinda nice, but I got the *exact* same thing with TCollection and
TCollectionItem with only about 5 extra lines of code. And IMHO I think I
prefer being forced to subclass like this because A) makes code maintenance
better (anything more explicit is easier to read than shortcuts) and B)
makes extensibility all that much easier.
Sooo, I am trying to learn about how Generics can be used _outside_ the usual
Collection example. There's *got* to be a real powerful use for them that
I'm just not seeing because I lack the experience in it. But as it is right
now, I don't really care if Generics or not in Delphi since my TCollections
work just fine and provide the same safe-casting results...
-BKN
 

Re: Generics + D2007/win32

Quote
Once you get used to a language that supports genericity, it is
exceptionally hard to work in any other way - at least if you want
compiler enforced type-safety.

You've got plenty of experience with Generics, clue me in to what I'm
missing. How are generics any different from subclassing TCollection and
TCollectionItem? I am sure there's more that I am just not seeing right now,
but no ones been able to give me a concrete example that really helps me
"get" Generics...
Don't get me wrong, I like using Generics, but there's got to be more than
just the Collection example...
-BKN
 

Re: Generics + D2007/win32

Quote
Oh, I agree, but there's got to be *more* than just making collections
easier to code.
Well sure, but collections are the most common use of generics. Go over to
.oodesign to see what Joanna Carter does with them in her OPF/MVP frameworks :-)
Quote
it makes it *very* explicit as to what I am trying to do
So does generics.
Like many other language features, this is just a neater way to do things. It's
not going to result in a huge jump in your productivity all of a sudden. It also
means you can cut down somewhat on your unit tests, although I still haven't
made up my mind by how much.
Cheers,
Jim Cooper
_____________________________________________
Jim Cooper XXXX@XXXXX.COM
Skype : jim.cooper
Tabdee Ltd www.tabdee.ltd.uk
TurboSync - Connecting Delphi to your Palm
_____________________________________________
 

Re: Generics + D2007/win32

Quote
In either case a generic is a convenient way of saving me some typing.
Yes.
Quote
The problem is that such conveniences ime also act to reduce the need
for THINKING.
I don't quite see why. I find it focusses mine.
Quote
Perhaps my public/protected exposure is actually inappropriate.
Sure, but that is an issue with or without generics. With generics at least you
only have to fix it in one place :-)
Quote
Whenever I starting thinking how much I'd like to use a generic I
give myself a slap and tell myself to start thinking about the problem
I'm trying to solve - not how a bit of syntactic sugar could save me
some typing.
I think that is a fair approach (I personally prefer to slap a minion though <vbg>)
Cheers,
Jim Cooper
_____________________________________________
Jim Cooper XXXX@XXXXX.COM
Skype : jim.cooper
Tabdee Ltd www.tabdee.ltd.uk
TurboSync - Connecting Delphi to your Palm
_____________________________________________
 

Re: Generics + D2007/win32

Quote
Do you not like using TCollection and TCollectionItem?
You get really, really {*word*99}py sorting performance with TCollection,
unfortunately. I had to do evil things to access the (private) internal TList in
TCollection to get acceptable performance. IIRC it is to do with the way
indexing is done.
Quote
Using your Person list example, if I was required to know how many people in
my list that had a valid address, it is just a new public function on the
TPersonCollection class.
That's certainly one place to put it. On the other hand you could use an Iterator...
Cheers,
Jim Cooper
_____________________________________________
Jim Cooper XXXX@XXXXX.COM
Skype : jim.cooper
Tabdee Ltd www.tabdee.ltd.uk
TurboSync - Connecting Delphi to your Palm
_____________________________________________
 

Re: Generics + D2007/win32

Quote
1) I need type safety because my implementation has a public (or
protected) exposure so I need to ensure that I (or someone else)
respects my type restrictions.

But what's wrong with simply subclassing TCollection and TCollectionItem for
this? I thought that was the whole purpose for those classes...
-BKN
 

Re: Generics + D2007/win32

Quote
I was more talking about situations where coding starts on day 1.
I'm fine with that approach too. Evolving an application is sometimes your only
choice. As long as you know that is what you're doing (and you know what you're
doing, I suppose) it is fine.
Management often have a problem with agile approaches though. It can not be drawn
on a Gantt chart :-)
Cheers,
Jim Cooper
_____________________________________________
Jim Cooper XXXX@XXXXX.COM
Skype : jim.cooper
Tabdee Ltd www.tabdee.ltd.uk
TurboSync - Connecting Delphi to your Palm
_____________________________________________
 

Re: Generics + D2007/win32

Quote
Of which Pascal is based on IIRC...
Ada was designed post Pascal (by some time). Generics in Ada worked without it
being object oriented, although I believe it is OO nowadays.
Cheers,
Jim Cooper
_____________________________________________
Jim Cooper XXXX@XXXXX.COM
Skype : jim.cooper
Tabdee Ltd www.tabdee.ltd.uk
TurboSync - Connecting Delphi to your Palm
_____________________________________________
 

Re: Generics + D2007/win32

Quote
How are generics any different from subclassing TCollection and
TCollectionItem?
It's the same sort of thing, except that the subclassing is done at runtime, and
you don't have to do it. So for situations like OPF users are in, where you want
zillions of type-safe collections, it is a big saving on time. Also, you can
start defining things like iterators over collections in a generic way, so you
don't have to do that as often either.
If you're writing frameworks for outsiders, this ability means your framework is
instantly extensible to use classes you have never seen without the need for the
users to subclass or implement interfaces.
I'm not sure you should be looking for some road to Damascus moment :-)
Cheers,
Jim Cooper
_____________________________________________
Jim Cooper XXXX@XXXXX.COM
Skype : jim.cooper
Tabdee Ltd www.tabdee.ltd.uk
TurboSync - Connecting Delphi to your Palm
_____________________________________________
 

Re: Generics + D2007/win32

Quote
Well sure, but collections are the most common use of generics. Go over to
.oodesign to see what Joanna Carter does with them in her OPF/MVP
frameworks :-)

Will do, thanks.
-BKN