Difference Between Array & Tuple for Large App

  • Context: Undergrad 
  • Thread starter Thread starter mikestampone
  • Start date Start date
  • Tags Tags
    App Array Difference
Click For Summary

Discussion Overview

The discussion revolves around the distinctions between arrays, tuples, and sets in programming, particularly in the context of naming conventions for a large application. Participants explore the appropriate terminology for describing collections of items and the implications of these terms in programming languages.

Discussion Character

  • Exploratory
  • Technical explanation
  • Conceptual clarification
  • Debate/contested

Main Points Raised

  • One participant seeks clarification on the differences between arrays and tuples, questioning whether they are the same and how to name them descriptively.
  • Another participant defines a tuple as an ordered list of items and describes a set as a collection of distinct items with no specified order, noting that an array can be multi-dimensional.
  • A participant inquires about the appropriate term for the number of items in a tuple or set, considering options like count, size, and cardinality.
  • Discussion includes references to Wikipedia entries on tuples and sequences, with one participant expressing uncertainty about the terminology used for elements in tuples.
  • Another participant mentions MATLAB's use of "length" to refer to the number of items in a collection, while also noting potential ambiguities with the term "length" in vector contexts.
  • One participant expresses a preference for using "length" throughout their program, while another discusses the commonality of "size" in various programming languages and its potential ambiguity regarding bytes.

Areas of Agreement / Disagreement

Participants generally agree on the definitions of arrays, tuples, and sets, but there is no consensus on the best terminology for describing the number of items in these collections. Multiple viewpoints on terminology remain unresolved.

Contextual Notes

Participants express uncertainty about the implications of using different terms for the number of elements, particularly in relation to programming languages and potential ambiguities in terminology.

Who May Find This Useful

Programmers and software developers interested in naming conventions and data structure terminology in the context of large applications may find this discussion beneficial.

mikestampone
Messages
14
Reaction score
0
I am wondering if anyone can describe to me the correct use of a couple words. I am programming a very large application, and I like to name my variables so that they are very descriptive. Before I begin, I would like to know what is the difference between an array and a tuple? Are they the same? If I have a list of symbols, such as <B,0,1>, is it more descriptive to say "symbol array", or "symbol tuple"? Also, as all C programmers know, I will need to be naming the array size in a separate variable. Should I say "symbol tuple size", "symbol array size", or something else? What about for sets? "symbol set" and "symbol set size"? Or is there something better? Normally I would just name them whatever, but this application is gigantic, and I want to make sure I get the naming right the first time. Thanks all.
 
Physics news on Phys.org
A tuple, also called a sequence, is an ordered list of items, such as (0,1,1), which is a different tuple from (1,1,0) and (0,1).

A set is a collection of distinct items with no specified order, so {0,1} represents the same set as {1,0} and {0,1,1}.

An array is a collection of items ordered in any number of dimensions. For example, a tuple is a 1-dimensional array (it takes one index to locate an item), and a matrix is a 2-dimensional array (it takes two indices to locate an item).
 
Thank you Rasalhague :) That clears up a lot. What about the number of items in a tuple or set. Do I say count, size, cardinality, or something else. I am not sure on how to say "the number of elements" in a single word. Is it different for sets and tuples?
 
The Wikipedia entry Tuple talks about the elements and length of a tuple. The Wikipedia entry Sequence talks about the members, elements or terms of a sequence, and about its length. (The tuple article says that a tuple is a sequence; and the sequence article says that a sequence is also called a tuple.) So length looks promising - but maybe someone can give us a more definitive answer. Wolfram Mathworld doesn't go into that much detail.

I've seen several ways of defining tuples in terms of sets. For example, some sources define the tuples recursively using nested sets like this:

(a,b) = {a,{a,b}}
(a,b,c) = ((a,b),c) = {{a,{a,b}},{(a,b),c}} = {{a,{a,b}},{{a,{a,b}},c}}

or if the possibility of a 0-tuple is included:

(a,b) = {{Ø{Ø,a}},{{Ø,{Ø,a}},b}}

and then define a function as a tuple (D,C,r), where D and C are sets, the domain and codomain of the function, and r is the rule relating them. But an alternative approach defines a sequence as a function from the set {1,2,...,n} to a set S, and I don't know how a function is defined in this latter view.

This makes me hesitate to talk about the "elements" of a tuple, in case a tuple is really a set whose elements are other sets. So instead, I've been calling them "terms" or "entries" or more vaguely "items". Maybe I'm being pernickity there, and I don't suppose there's really any ambiguity, but I'm just learning about these things, and I want to get it right... Obviously the Wikipedia writer didn't see any contradiction with calling them elements or members.
 
Thanks again Rasalhague. I will use "length" throughout my program :)
 
You're welcome.

MATLAB calls it length too:

>> a=[1 1 1];
>> length(a)

ans =

3

A possible source of ambiguity, in some contexts, is that the magnitude or norm of a vector is often referred to, informally, as its length. In the case of the vector space of real coordinate vectors with the usual rules:

\text{norm}(\mathbf{a})=\sqrt{\mathbf{a} \cdot \mathbf{a}}=\sqrt{\sum_{i=1}^{n}(a_i)^2}

>> a=[1 1 1];
>> norm(a)

ans =

1.7321

i.e.

\sqrt{3}
 
Luckily, my program is not going to be using vectors, so ambiguity in this case will not be a problem. Although it will be good to consider this ambiguity in the creation of future programs which may involve vectors. Thank you for taking the time to answer my question so in-depth. I really appreciate your guidance.
 
Size is a common term for the number of elements in a collection. It's enouraged by the language too -- C++ containers use size() to get the number of elements they contain, and C has the type size_t. (Though I suppose in a few contexts, there could be an ambiguity about size referring to number of bytes -- e.g. that's what sizeof returns)

Of course, length is also common. Java uses that for its arrays, and python uses the abbreviation len for all of its container types.
 
Thanks Hurkyl. I will be using length. If I am coding with a vector data type I will default to size. It is interesting that you noted the ambiguity of size referring to a number of bytes. That is actually why I started this thread :) I was looking for something different than size, because I knew size could mean the number of bytes, in C language.
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 4 ·
Replies
4
Views
5K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 31 ·
2
Replies
31
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
Replies
6
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K