[prev in list] [next in list] [prev in thread] [next in thread] 

List:       xmlbeans-dev
Subject:    Re: No Collections API use?
From:       David Waite <mass () akuma ! org>
Date:       2004-08-13 4:46:33
Message-ID: C11D2BD2-ECE3-11D8-8F78-000A95C89D86 () akuma ! org
[Download RAW message or body]


On Aug 12, 2004, at 8:18 AM, David Smiley wrote:

> I read that document but JDK 1.5 support really is unrelated to what 
> I'm talking about.  The more I think about it, Collections API use is 
> clearly the right choice.  I don't buy the speed trade-off argument 
> Radu makes either.  We're not talking about low-level parsing or 
> graphics manipulation code; we're talking about high-level programming 
> abstractions.  If after this, one /still/ thinks we should use arrays, 
> then I ask to those people, when *does* one use Collections?

Actually, the speed trade-off was mine. This is due to arrays being a 
'quasi-native' type in java, vs. collections which are just objects 
with references to one another forming a data structure.

Really though, Collections are used for manipulation, correlation, and 
indexing of data; arrays do not handle any of these well. On the other 
hand, collections in java (< 1.5) have a major flaw, in that they leave 
the contained data completely untyped.

For example: given the following

...
<xs:ComplexType name='FooType'>
	<xs:Sequence>
		<xs:Element name='Name' type='xs:string'/ maxOccurs='unbounded'>
	</xs:Sequence>
</xs:ComplexType>
...

You can say right now my FooType object has a getNameArray() method 
which returns a String[]. You could change it to instead return an 
Iterator implementation, then write code like the following

Iterator it = foo.getNameIterator();
while (it.hasNext())
{
	String name = (String) it.next();
	...
}

Unfortunately, when someone on the project changes the schema file so 
that Name is now of BarType, your code will successfully compile, and 
everything may look fine until you see a ClassCastException during your 
regression testing.

-David Waite
["smime.p7s" (application/pkcs7-signature)]

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic