Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Random question - do programming languages other than Java feature "vectors"?

Random question - do programming languages other than Java feature "vectors"?
Thread Tools
Kibon
Fresh-Faced Recruit
Join Date: Sep 2003
Location: Canada
Status: Offline
Reply With Quote
Nov 2, 2003, 03:39 AM
 
...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?
     
T Walls
Fresh-Faced Recruit
Join Date: Aug 2001
Status: Offline
Reply With Quote
Nov 2, 2003, 09:10 AM
 
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.
     
Arkham_c
Mac Elite
Join Date: Dec 2001
Location: Atlanta, GA, USA
Status: Offline
Reply With Quote
Nov 2, 2003, 11:40 AM
 
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
     
DaGuy
Senior User
Join Date: Oct 2000
Location: Lawrence, KS
Status: Offline
Reply With Quote
Nov 2, 2003, 12:08 PM
 
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. )
     
Kibon  (op)
Fresh-Faced Recruit
Join Date: Sep 2003
Location: Canada
Status: Offline
Reply With Quote
Nov 2, 2003, 04:23 PM
 
Thanks everyone.

I won't inquire further into the threading issues, will just deal with it when I come to it in programming.
     
TampaDeveloper
Dedicated MacNNer
Join Date: Nov 2003
Status: Offline
Reply With Quote
Nov 2, 2003, 10:01 PM
 
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!
     
off/lang
Forum Regular
Join Date: Nov 2002
Location: PVD/MSP
Status: Offline
Reply With Quote
Nov 3, 2003, 12:29 AM
 
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.)
dearinter.net consensus life coaching.
     
johnMG
Registered User
Join Date: Oct 2003
Status: Offline
Reply With Quote
Nov 3, 2003, 01:31 AM
 
Has Vector been standardized as part of the C++ language

Yes: std::vector.
     
Gul Banana
Mac Elite
Join Date: May 2002
Status: Offline
Reply With Quote
Nov 7, 2003, 10:58 AM
 
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 Links
Forum 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
Top
Privacy Policy
All times are GMT -4. The time now is 06:00 PM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,