Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

MarkCollette

macrumors 68000
Mar 6, 2003
1,559
36
Toronto, Canada
Again, I was talking about a vector concept, not the java.util.Vector class.

But, a couple points of rebuttal are in order, so show that Vector is not defunct :)

- All programs I write a multi-threaded. True, one should use specific synchronization chokepoints, and not synchronise every little datastructure... But a lot of times, all that chokepoint does is add or remove items to/from a Vector (producer/consumer problems), so Vector still has some utility.

- A Vector will have less overhead than a synchronized List wrapping an unsynchronised List.

- Using a Vector gives the signature type that this is synchronised, whereas giving a List that happens to be synchronised does not have the same typing information. I don't mean some compiler thing, I mean that programmers can see at a glance that it's synchronised.

- Building on your point about old JVMs. Vector versus List is both a performance tradeoff and a compatibility tradeoff. Vector works everywhere and is a bit slower, and List works most places and is a bit faster. I will always take slower if it means that code can reach more people. Who knows what esoteric platform, with an old JVM, could benefit from running your app? I try to code to the lowest common denominator possible, because there's more profit in being able to sell to more people.
 

Compile 'em all

macrumors 601
Apr 6, 2005
4,131
359
ChrisBrightwell said:
State your source.

Sun's documentation says nothing about java.util.Vector being deprecated:
http://java.sun.com/j2se/1.5.0/docs/api/java/util/Vector.html

Nor does the deprecated list mention java.util.Vector:
http://java.sun.com/j2se/1.5.0/docs/api/deprecated-list.html

You are right. Vector was moved and it now implements List. This was not
the case in JDK 1.1. Quoted from the Vector docs:
As of the Java 2 platform v1.2, this class has been retrofitted to
implement List, so that it becomes a part of Java's collection framework.
I still stand by my point though. If you need thread safety don't use Vector,
instead you should do:

ArrayList alist = new ArrayList();
List MyList = new java.util.Collections.synchronizedList(alist);

You can find more info here and here.

MarkCollette said:
I will always take slower if it means that code can reach more people. Who
knows what esoteric platform, with an old JVM, could benefit from running
your app? I try to code to the lowest common denominator possible,
because there's more profit in being able to sell to more people.
Totally agree, but only when doing client-side programming :D
 

dunc85

macrumors regular
Jul 23, 2006
112
0
Interesting. When I completed my undergraduate Degree, in the first year we had to do similar stuff as this. However, we had to write our own stuff from scratch - i.e. we had to write our own implementation of a LinkedList, or the Shuffle method, rather than using those supplied by the Java API.

At the time, we saw it as a slightly pointless exercise of reinventing the wheel, but reading this post makes me realise it was totally worthwhile.
 

bousozoku

Moderator emeritus
Jun 25, 2002
16,120
2,397
Lard
dunc85 said:
Interesting. When I completed my undergraduate Degree, in the first year we had to do similar stuff as this. However, we had to write our own stuff from scratch - i.e. we had to write our own implementation of a LinkedList, or the Shuffle method, rather than using those supplied by the Java API.

At the time, we saw it as a slightly pointless exercise of reinventing the wheel, but reading this post makes me realise it was totally worthwhile.

The thing is that you should be able to implement such a structure with any language, even if you have to modify it because the language doesn't implement some functionality.

Once you understand the why and how of things, you can use the supplied constructs with confidence, and in new and interesting ways.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.