1

When I write high-level documentation about what an algorithm does, I use the term "array" to refer to the data structure on which the algorithm operates even though the actual data structure is an std::vector. I feel that using the term "vector" in this context does not (to me) best convey the meaning I'm after which is "a sequence of elements with constant-time random access" or perhaps more generally "a dynamic array". Is there a convention or common documentation standard for this distinction of similar terms?

4
  • 2
    This is all confusing. C++'s map is not your LISP's Python's map. At the end of the day these are just words. I, for instance, really want to call some data structure a "ladder" ... just because.
    – Job
    Jun 9, 2011 at 23:14
  • 1
    The C++ standard uses the term Sequence to generically describe the sort of data structure you're talking about. A vector is both a Sequence and a RandomAccessContainer. Jun 9, 2011 at 23:45
  • 1
    I think I'd use "random access sequence." Jun 9, 2011 at 23:58
  • Does it have to be sequential? Except where necessary, I would use the term "container" or "collection" and let the implementations worry about the best technique for storing it. Jun 10, 2011 at 2:23

4 Answers 4

2

I don't know of any standard nomenclature, but like the OP, I prefer using "array" or "dynamic array" for something that has constant-time random access, without specifying the mechanism.

Even though STL uses the term "vector", I come from a mathematics/chemistry background, and do a lot of 2D/3D graphics. In those fields, when you say "vector" in a generic way, it has its linear algebra meaning: a point in an N-dimensional vector space. When I use "vector" in the STL sense, I'm always referring to that specific STL template container.

To me, "list" when applied to containers implies "linked list", which doesn't have constant-time random access. Like Neil Butterworth, I rarely use std::list.

2

First, know your audience!

I understand from where are you coming from, but If you are writing to C++ people, Use vector. A C++ programmer would know what you mean by vector. Within the C++ context, If you are calling a vector an array, it might be confusing to some folks. IF you still want to use the name "Array", then I will suggest to make a note that you make no distinction between static and dynamic array.

If you are talking to non-technical people, then use the word list or something easier than convey the message (I would still try to define vector because they might get technical later on.)

Good luck!

1
  • If you are writing to any decent programmer, Use array. May 8, 2013 at 20:06
1

We all have our little coding idiosyncrasies, but... come on man!

You're using a vector, why would you call it an array? They're two different things.

An "array" is not a universally known concept. That is, you can't walk up to a random person, ask them what an array is, and expect them to know. So how does that particular word convey the concept of "a collection of elements with constant-time random access" better than "vector"?

Have more faith in your colleagues. Anyone looking over your code who knows what an array is should know what a vector is. And if they don't, you have bigger problems.

2
  • I'm not sure why but I thought of "array" as a more universally known term, but you might be right on this. Thanks +1 Jun 10, 2011 at 0:35
  • Using vector to people who don't know C++ (or other languages that use this unfortunate terminology) for "a collection of elements with constant-time random access" is a joke. Vectors are canonically mathematical objects, often of a fixed dimension. Use array or list or sequence. Of course, this doesn't apply if you are actually coding in such a language. May 8, 2013 at 20:11
1

Interesting. I always use the term "list" as it is (almost) the most degenerate form of a collection, and so the most general. I almost never use std::list in my actual C++ code. however. As a real example from my own code:

 typedef std::vector <unsigned int> FieldList;
7
  • Why you don't use FieldVector? Keep in mind that the first thing that most people will not think is that you call "vector" as "list" or "string" as "int".
    – Armando
    Jun 9, 2011 at 23:56
  • @Armando Because I might want to turn it into a set? Or a deque? It's just a bunch of stuff, so I use the most general term - a list. Jun 10, 2011 at 0:00
  • @Neil, Keep in mind that List is a well defined data structure. I know where you are coming from and is a good idea to do typedef rather than hardcore the template type. I used typedef for STL containers as well. I think Scott Meyers used the word "Container" for generic data structure.
    – Armando
    Jun 10, 2011 at 0:06
  • Isn't the term "range" used a lot when talking about generic algorithms? Anything with a beginning and an end... is that too general for the OP's situation?
    – Kerrek SB
    Jun 12, 2011 at 9:52
  • @Kerrek Range is used to refer to that - a range inside a container, which might be over the entire contents, or might not. What's being asked about here is a name for the container itself. Jun 12, 2011 at 9:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.