Re: Vector (was Re: Change character in string)
Andreas Leitgeb wrote:
The contest is still open, with (now corrected):
List<Foo> lf= Collections.synchronizedList(new ArrayList<Foo>())=
List<Foo> lf= new Vector<Foo>();
Scores so far:
half a point to the former for being in line with other
Collection implementations' synchronized wrappings.
Being consistent with collections is worth at least a full point.
quarter of a point to the latter for being shorter to write.
No points for being shorter to write. That's just laziness and not
half a point to the latter for being "slightly faster" according to S=
I don't believe it, and even if true I wouldn't give that more than a
hundredth of a point. Where is this documented, and under what
conditions were the speed tests made?
I.e.: No strong points on either side.
One point to 'synchronizedList()' for being able to wrap
implementations other than 'ArrayList'. That way if one needs to
refactor there's less engineering effort to it.
One point to 'synchronizedList()' for not pulling in 'Enumaration',
about which even Sun says:
NOTE: The functionality of this interface is duplicated by the Iterator i=
In addition, Iterator adds an optional remove operation, and has shorter =
names. New implementations should consider using Iterator in preference t=
Andreas Leitgeb wrote:
What's the point of this?
My goal is to convince you to not take every mention of Vector as a
trigger to post how the hell bad it is. It isn't always. It's that
only if context is clearly free of synchronisation requirements, or
some poster also uses Vector for variable or (even worse) parameter
The real problem is that people usually use 'Vector' where
synchronization is not needed, i.e., in lieu of an unsynchronized
'ArrayList'. Getting in the habit of never using 'Vector' prevents
that, a whole other point in favor of eschewing 'Vector'.
I think the burden is on 'Vector' to justify itself, and that it
should not be used any more. Even were it a raw tie, which I don't
believe it is, then 'ArrayList' should win absent a clear, strong
advantage to 'Vector'.
However, I see at least a four-point advantage to using a non-Vector
'List', so I'm going to continue to advocate for that.
Given that 'ArrayList' is a leaner, more compliant implementation of
'List' than is 'Vector', that it has the flexibility of being
unsynchronized or synchronized, that it can easily be replaced by
other 'List' implementations in either scenario, and that 'Vector'
offers no advantages over other 'List' implementations, and that using
'Vector' is socially equivalent to using 'thou' in modern American
Standard English and is just as archaic and strange, I say eschew
Vector where legacy code doesn't require it.