11-18-2005, 12:34 PM | #1 (permalink) |
Location: Waterloo, Ontario
|
Whose ideas was it to call std::vector a vector!
Thanks to the STL, I can't include the name "vector" in my variables without someone being confused about whether I mean a mathematical vector or an STL vector container.
Now, I would be content to have small difficulties in life come about due to the complexities of life but this is not such a case! Whoever came up with these STL names had no clue what a "vector" is but thought the name was cool and used it... Without realizing that, perhaps, a lot of people would like to code vectors using C++. So, who came up with this container name? Has anyone else experienced the same frustration over this or a similar situation? |
11-18-2005, 12:47 PM | #2 (permalink) | |
Devoted
Donor
Location: New England
|
At least those variables aren't being confused for rats..
Quote:
__________________
I can't read your signature. Sorry. |
|
11-18-2005, 03:05 PM | #4 (permalink) | |
Lover - Protector - Teacher
Location: Seattle, WA
|
I've never really found a good explanation for why they re-used a perfectly good term for things with a magnitude and a direction to mean "a dynamic array," so I'll agree with you there.
However, couldn't you use namespaces, such as use mynamespace; instead of STL so that Vector is recognized as YOUR vector, rather than the STL vector? The entire purpose of a namespace is to prevent this type of naming conflict, isn't it? EDIT: Added an example: Quote:
__________________
"I'm typing on a computer of science, which is being sent by science wires to a little science server where you can access it. I'm not typing on a computer of philosophy or religion or whatever other thing you think can be used to understand the universe because they're a poor substitute in the role of understanding the universe which exists independent from ourselves." - Willravel |
|
11-18-2005, 04:56 PM | #5 (permalink) |
Crazy
|
Why dont you just extend the vector class to add magnitude, dot, and cross methods?
I do agree with you 100% on the vector being a poor choice. I recently coded a matrix class with gaussian reduction, but I didnt run into this. I wish the math class in every language went beyond highschool level mathematics. Still, I think java used an arrayList, so java is better in this instance. However, I now end up doing everything in XML, XSD, XSLT, and SVG. I create file or strings, and an engine does all the processing. Not really fun, but there are a lot of options for creative solutions....so its not so bad. |
11-18-2005, 10:56 PM | #6 (permalink) |
Junkie
Location: San Francisco
|
It makes sense to me; it's a collection of values, and I doubt the term's use in computer science started with STL. Not exactly the same as a mathematical vector since the same operations aren't defined, but you could easily define them to make it more like one (which can also have any number of values n-dimensional). Don't blame the creators of STL for your own confusion (seems to be a common thing with C++ in general, and like L.A., I find it my duty to defend it); I'm sure there are plenty of mathematicians getting along fine with it. =P
__________________
"Prohibition will work great injury to the cause of temperance. It is a species of intemperance within itself, for it goes beyond the bounds of reason in that it attempts to control a man's appetite by legislation, and makes a crime out of things that are not crimes. A Prohibition law strikes a blow at the very principles upon which our government was founded." --Abraham Lincoln Last edited by n0nsensical; 11-18-2005 at 11:04 PM.. |
11-19-2005, 03:49 AM | #7 (permalink) | |
Location: Waterloo, Ontario
|
Quote:
Code:
ContinuousFunction AffineTransform::Apply(ContinuousFunction vector) { return mFactorField * vector + mTranslationVector; } ...and for what? In what manner is std::vector a vector? It's a rather non-descriptive name. Not to mention that I have a few other complaints about the STL naming conventions--along those same lines! |
|
11-19-2005, 03:49 AM | #8 (permalink) | ||
Location: Waterloo, Ontario
|
Quote:
Quote:
A vector is merely an element of a set that follows the vector axioms. So, for instance, the most popular vector space, aside from the Cartesian vectors everyone has already mentioned, is the set of continuous functions. Interestingly enough, the set of sinusoidal waves of integral frequencies forms a basis for this set! This is the basis of fourier analysis and is very important for signal processing, for which there is plenty of software written! Can continuous functions be represented as n-tuples of values? Not really... Let's face it, std::vector has nothing to do with vectors! Why not call it exactly what it is: an array. What would have been wrong with std::array? |
||
11-19-2005, 04:19 AM | #9 (permalink) |
Junkie
Location: San Francisco
|
I very well understand that a vector is an element of a vector space, thanks, but it still seems obvious where the name came from. Sure, they could have used array, but either way I don't think the name of that class should cause substantial confusion as in general you shouldn't need to put a variable's type in its name to make your code understandable..at best that's just a longer version of hungarian notation which is hardly universal.
__________________
"Prohibition will work great injury to the cause of temperance. It is a species of intemperance within itself, for it goes beyond the bounds of reason in that it attempts to control a man's appetite by legislation, and makes a crime out of things that are not crimes. A Prohibition law strikes a blow at the very principles upon which our government was founded." --Abraham Lincoln |
11-29-2005, 04:08 PM | #10 (permalink) |
Crazy
|
When I learned about the Vector data type, it was described to me as a "carrier class". Having a biology background I thought of a mosquito, as Redlemon explained.
One reason it's not called std::array is becuase they store things two different ways. Arrays use contiguous memory while Vectors don't. This isn't always the case, but following convention, it makes sense for things not to be called an array. Vectors and arrays are apples to oranges. Sure, they do the same things, but they're implemented in vastly different ways which make them completely seperate concepts. |
11-30-2005, 12:24 PM | #11 (permalink) | |
Location: Waterloo, Ontario
|
Quote:
|
|
11-30-2005, 01:52 PM | #12 (permalink) |
I am Winter Born
Location: Alexandria, VA
|
Vectors don't store their elements in contiguous memory - it wouldn't be possible for them to be dynamically resized if that was the case.
For instance, if you allocate two vectors of length 10 at the start of your program, chances are they'll be stuck next to each other in memory. Later on, you decide you want to add another 100 elements to the first vector. That space isn't available next to the vector, so what's it do? It tries to find space elsewhere in memory and then sets up a pointer for the behind-the-scenes vector math so that when the iterator goes from 10 to 11, it knows to jump to the new segment of memory.
__________________
Eat antimatter, Posleen-boy! |
11-30-2005, 02:01 PM | #13 (permalink) |
Crazy
|
Nope, Vectors don't store their elements in contiguous memory. Each element of a Vector is a reference to an object somewhere else in memory. Depending on the language being used, the Vector's reference list may or may not be stored in contiguous memory. However, this doesn't change the function of the Vector data type. Additionally, the footprint for a reference ("pointer" for c++ people) is very small, so this quirk is considered a trait of the language itself rather than the Vector.
Compare declaring a Vector which will hold 20 elements versus declaring an array of the same size. Assuming an integer is 4 bytes and a reference/pointer/memory address is 2 bytes. Note: Fictional scenario int[] array = new int[20]; sets aside 4*20 blocks of contiguous memory. Vector vector = new Vector(20); sets aside 2*20 blocks in contiguous memory (depending on the implementation/language). To fill up the vector an additional 80 bytes are required somewhere else in memory. The original 40 bytes point to the various places each int is placed. |
11-30-2005, 03:48 PM | #14 (permalink) |
Junkie
Location: San Francisco
|
I thought the STL vector was just an interface and each STL implementation of vector could theoretically be different. What I'm getting at is I don't see any reason why the elements of a vector couldn't be stored in contiguous memory, though actual implementations would find better ways. That wouldn't stop it from being resized because it could simply allocate a larger block of contiguous memory and copy the existing elements over to it. So are you talking about a spec or definition somewhere that says this or the de facto way of implementing it?
__________________
"Prohibition will work great injury to the cause of temperance. It is a species of intemperance within itself, for it goes beyond the bounds of reason in that it attempts to control a man's appetite by legislation, and makes a crime out of things that are not crimes. A Prohibition law strikes a blow at the very principles upon which our government was founded." --Abraham Lincoln Last edited by n0nsensical; 11-30-2005 at 03:53 PM.. |
11-30-2005, 05:03 PM | #15 (permalink) | |
Location: Waterloo, Ontario
|
Quote:
Having said that, after a modicum of research (asking someone who knows), I have discovered that std::vector need not be implemented using contiguous memory. This may not be true in the future since the STL container that does implement contiguous memory, std::valarray, is in the process of being deprecated in favour of std::vector, since almost all implementations of it do exactly that (use contiguous memory). In answer to Pragma's reasoning, it is false. There's nothing about contiguous memory that makes it impossible to dynamically resize the container. Yes, it might require a lot of copies but there are no constraints to the execution time of insertion for std::vector, so that's okay (in terms of conformance). This is beside the point. Because std::vector need not be implemented as contiguous memory, that might explain why "array" wasn't used as a name. However, I still feel that "vector" was a poor name in that it's not a vector in any sense of the word. At least the std::vector interface shares almost all of the qualities of an array. So much so that I say it is still a much better name than "vector"... |
|
11-30-2005, 06:28 PM | #16 (permalink) |
I am Winter Born
Location: Alexandria, VA
|
What I was going at - but failed to mention - is what happens if you have an array that's larger than your largest block of contiguous memory? Using a vector, it's possible to store that, having it broken into chunks scattered wherever there's space, as opposed to simply going "Hrm, we need to add elements, okay, let's go find a new chunk of free memory that's current+50 bytes."
That's what happens when I don't completely explain myself
__________________
Eat antimatter, Posleen-boy! |
11-30-2005, 07:07 PM | #17 (permalink) | |
Location: Waterloo, Ontario
|
Quote:
|
|
Tags |
call, ideas, stdvector, vector |
|
|