Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 08-03-2003, 05:53 PM   #1 (permalink)
Belisarius
Java fanboy
 
Belisarius's Avatar
 
Join Date: Aug 2003
Posts: 1,166
Belisarius is on a distinguished road
Why Vector

I've been poking around a few Java forums, and notice a lot of people use Vector. Why? It's slow and designed for threaded operations. Why don't more people use ArrayList? I use Vectors nowadays only when I want to synchronize data across threads.
__________________
GitS
Belisarius is offline   Reply With Quote
Old 08-03-2003, 05:57 PM   #2 (permalink)
npa
Code Monkey
 
Join Date: Jul 2003
Location: canada
Posts: 82
npa is on a distinguished road
Re: Why Vector

Quote:
Originally posted by Belisarius
I've been poking around a few Java forums, and notice a lot of people use Vector. Why? It's slow and designed for threaded operations. Why don't more people use ArrayList? I use Vectors nowadays only when I want to synchronize data across threads.
Because somewhere, someone thought it was a good
idea...

It baffles me too (but my teacher in school told me to
use them).
__________________
direct entry file specification.
npa is offline   Reply With Quote
Old 08-03-2003, 06:04 PM   #3 (permalink)
Belisarius
Java fanboy
 
Belisarius's Avatar
 
Join Date: Aug 2003
Posts: 1,166
Belisarius is on a distinguished road
Well, my professor basically thinks of Vector as a mistake. And if anyone should know, it's him, being that he basically wrote Collections.

It's good having actually language designers as professors.
__________________
GitS
Belisarius is offline   Reply With Quote
Old 08-06-2003, 07:42 PM   #4 (permalink)
technobard
Centurion Nova Prime
 
technobard's Avatar
 
Join Date: May 2002
Location: Oak Park, IL (USA)
Posts: 287
technobard is on a distinguished road
I could be wrong on this, but I think Vector came out before ArrayList. A lot of older sample code probably uses Vector. When I started using Java, I took the 5-day class from Sun (which didn't include much, if any, info on Collections). The rest I picked up as I used it or needed it. I use a lot of Vector and Hashtable, even though I know that ArrayList and HashMap are the preferred alternatives. It's just habit and laziness. The execution speed thing only matters when you're doing something so speed intensive that you notice. If you're not writing that kind of code, which a lot of people aren't, you can't tell the difference.
technobard is offline   Reply With Quote
Old 08-06-2003, 08:55 PM   #5 (permalink)
Belisarius
Java fanboy
 
Belisarius's Avatar
 
Join Date: Aug 2003
Posts: 1,166
Belisarius is on a distinguished road
Granted, there's no point in going back through all your old code to replace Vector with ArrayList when the old code works, but that doesn't explain why people continue to use it (and even worse, tell other people to use it).

It's just a flawed class (which, BTW, isn't even going to really exist in 1.5, it's just going to be a front-end to a new collection). It's synchronized but not thread safe. Ugh.
__________________
GitS
Belisarius is offline   Reply With Quote
Old 08-07-2003, 07:53 AM   #6 (permalink)
technobard
Centurion Nova Prime
 
technobard's Avatar
 
Join Date: May 2002
Location: Oak Park, IL (USA)
Posts: 287
technobard is on a distinguished road
Quote:
Originally posted by Belisarius
...but that doesn't explain why people continue to use it (and even worse, tell other people to use it).
Laziness, inertia, etc. Take your pick. Telling other people to use it is probably just not knowing any better. Personally, I try to tell people to use HashMap instead of Hashtable even though I've never done it. And I usually mention (if prompted), that there are better alternatives to Vector. But if I need to crank out a quick utility or something, the chances are good that I won't take my own advice. I've done it a hundred times before, I know the syntax, and I know it will work for what I'm doing.

I would hope that professional programmers / developers are better about this sort of thing. I think you mentioned that you were a student, so you probably fall into this category because of your intended profession. I'm an ex-engineer turned DBA (many, many moons ago) who happens to program occasionally. These days, mostly I write things to make my life easier. I've written enough code over the years in enough languages that I can usually figure out how to write anything I need. But no one would ever accuse me of following programming best practices. I suspect there are a lot of people out there like me. Maybe that explains some of what you're seeing.

Later.
technobard is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
vector of vectors zergmuncher Standard C, C++ 5 05-15-2003 08:15 AM
Need an alphabetic sort algorithm SkittlesAreYum Java 4 05-08-2003 11:02 PM
comparing words to those in a vector? sofa Standard C, C++ 3 03-31-2003 10:57 AM


All times are GMT -8. The time now is 08:47 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting