|
|
Random question - do programming languages other than Java feature "vectors"?
|
|
|
|
Fresh-Faced Recruit
Join Date: Sep 2003
Location: Canada
Status:
Offline
|
|
...I'm learning Java right now (as well as learning to program), and we just covered both arrays and vectors.
Vectors seem a bit redundant to me, as arrays are used for the exact same purpose. There is also a bit of additional work involved with vectors, as you need to "cast" the objects that you are pulling out of the vector, whereas an array is pre-defined as to which data type you are storing (i.e. int, float, etc.). I'm not sure that the ability to store multiple data types in a vector is either needed or useful when coding, and this ability is about the only significant difference between arrays and vectors.
Thoughts?
|
|
|
|
|
|
|
|
|
Fresh-Faced Recruit
Join Date: Aug 2001
Status:
Offline
|
|
Originally posted by Kibon:
...I'm learning Java right now (as well as learning to program), and we just covered both arrays and vectors.
Vectors seem a bit redundant to me, as arrays are used for the exact same purpose. There is also a bit of additional work involved with vectors, as you need to "cast" the objects that you are pulling out of the vector, whereas an array is pre-defined as to which data type you are storing (i.e. int, float, etc.). I'm not sure that the ability to store multiple data types in a vector is either needed or useful when coding, and this ability is about the only significant difference between arrays and vectors.
Thoughts?
Yup. C++ has a large difference between vectors and arrays. Frankly, arrays are a bigtime pain in the butt, while vectors are the light. There is a lot more functionality in vectors in C++ such as getting the number of elements.
|
|
|
|
|
|
|
|
|
Mac Elite
Join Date: Dec 2001
Location: Atlanta, GA, USA
Status:
Offline
|
|
One other thing -- Vectors are thread-safe, while arrays are not. If you don't care about that, then arrays are faster.
Another point to mention is that Java 1.5 has Generics (aka parameterized types) which should increase performance of Vectors (and Enumerations and other similar types) and eliminate the need for casts.
|
Mac Pro 2x 2.66 GHz Dual core, Apple TV 160GB, two Windows XP PCs
|
|
|
|
|
|
|
|
Senior User
Join Date: Oct 2000
Location: Lawrence, KS
Status:
Offline
|
|
Originally posted by Kibon:
...I'm learning Java right now (as well as learning to program), and we just covered both arrays and vectors.
Vectors seem a bit redundant to me, as arrays are used for the exact same purpose. There is also a bit of additional work involved with vectors, as you need to "cast" the objects that you are pulling out of the vector, whereas an array is pre-defined as to which data type you are storing (i.e. int, float, etc.). I'm not sure that the ability to store multiple data types in a vector is either needed or useful when coding, and this ability is about the only significant difference between arrays and vectors.
Thoughts?
One thing that I keep in mind is that so many highly paid smart people must have a good reason for comming up with the vector class. Surely enough, vectors and arrays address different needs.
Java is intended to be somewhere between a statically typed and dynamic language. Therefore a container class that can store anything can solve many problems were you don't know the objects type until run-time. Interesting code in my opinion has these dynamic characteristics.
The fact that vectors are thread safe is absolutely key. Think about writing a highly multithreaded app say like Mail or the Finder, wouldn't it be nice to have a container class than store anything and not be corrupted by concurrent access?
Choice is good forcing everyone into one style of coding is not.
(
Last edited by DaGuy; Nov 2, 2003 at 09:04 PM.
)
|
|
|
|
|
|
|
|
|
Fresh-Faced Recruit
Join Date: Sep 2003
Location: Canada
Status:
Offline
|
|
Thanks everyone.
I won't inquire further into the threading issues, will just deal with it when I come to it in programming.
|
|
|
|
|
|
|
|
|
Dedicated MacNNer
Join Date: Nov 2003
Status:
Offline
|
|
Originally posted by T Walls:
Yup. C++ has a large difference between vectors and arrays. Frankly, arrays are a bigtime pain in the butt, while vectors are the light. There is a lot more functionality in vectors in C++ such as getting the number of elements.
Hi! It's been awhile since I've looked at C++. When I was using it, there were lots of frameworks that had custom implementations of something similar to Vector. Has Vector been standardized as part of the C++ language, or are we still dependant on a custom framework?
Thanks!
|
|
|
|
|
|
|
|
|
Forum Regular
Join Date: Nov 2002
Location: PVD/MSP
Status:
Offline
|
|
But surely no body has pointed out the truly import difference between Vectors and arrays:
Vectors are mutable. That is, their size can change. Arrays are instantiated to a specific size and that size cannot be exceeded.
(Also to note: if you don't care about Thread safety, ArrayLists are faster than Vectors and have the same benefits.)
|
|
|
|
|
|
|
|
|
Registered User
Join Date: Oct 2003
Status:
Offline
|
|
Has Vector been standardized as part of the C++ language
Yes: std::vector.
|
|
|
|
|
|
|
|
|
Mac Elite
Join Date: May 2002
Status:
Offline
|
|
There are equivalents of vector in almost every programming language. Very low level ones like C sometimes have only arrays instead. Arrays have the advantage of being the way the computer Actually Works, but vectors are MUCH more flexible and powerful for general use.
|
[vash:~] banana% killall killall
Terminated
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Forum Rules
|
|
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
|
|
|
|
|
|