Rosetta Code:Village Pump/Arrays: Difference between revisions

Only an array is an array
(Copy contents from Creating an Array)
(Only an array is an array)
 
(7 intermediate revisions by 4 users not shown)
Line 1:
{{Vptopic
|topic=Arrays
|summary=Discussion of just what exactly we mean by an array.
}}
In RC, Array tasks are not very organized. Let's see: [[Array]], [[Creating an Array]], [[Array Initialization]], [[Collections]], and a lot of examples in [[Creating an Array]] (mostly dynamic languages like Python) aren't really using Arrays, they are using just Lists, Vectors and etc. Arrays are not dynamic. A solution is create a [[Creating a List]] or etc. But other languages call it in a different way. This is not really a solution.
 
Line 11 ⟶ 15:
I advise being very careful. The problem is that language terminology varies wildly and permitted operations is, if anything, even more differentiated across the languages. What is an obvious merger for one might be a loss of an important subtlety for another. (It was the “aren't really using Arrays” that triggered this message, as it indicated that the author of it might be projecting how one language does things onto others, which is usually a mistake.) —[[User:Dkf|Donal Fellows]] 09:56, 30 July 2009 (UTC)
:I agree with this entirely. (Also, if we're going to be specific about the kind of data structure, I would suggest (as opposed to "contiguous memory"): consecutive numeric indexing, arbitrary size, and no greater than O(log n) element access time.) --[[User:Kevin Reid|Kevin Reid]] 11:35, 30 July 2009 (UTC)
 
:: As for element access time, that would be a sticky wicket. Some REXX interpreters have serial lookup for all variables (including array elements), some (if not most) have hashing techniques. Most REXX programmers don't know nor care. REXX may be one of the few languages that doesn't keep it's array elements in sequential order. The term then, consecutive numeric indexing, falls by the wayside in REXX. One can assign array elements consecutively (numerically), but that would be just an artifact. You'd have to add another one or two or three categories, and I struggle to think what they would be called: a.2=222; a.02=333; a.2.=444; a..2='omg'; g=.7; a.g=555; h='±'; a.h=666 --- all unique. I think grouping arrays by how the language supports them would get argumentative fast, depending on how one interprets the definitions and understanding on ''how'' a particular version of a language worked. Technically, REXX wouldn't even be invited to his party, as it doesn't have "true" arrays, but that doesn't stop anyone from using REXX's version of arrays: ''stemmed arrays''. They look, taste, feel, and smell like arrays, so, what the heck. -- [[User:Gerard Schildberger|Gerard Schildberger]] 19:37, 20 May 2012 (UTC)
 
:I think it would be fine to merge [[Creating an Array]], [[Assigning Values to an Array]], and [[Retrieving an Element of an Array]], mostly as a way to show off a language's built-in syntax for native arrays. I think some of the higher order array tasks ([[Select from Array]], [[Apply a callback to an Array]], [[Sorting an Array of Integers]], etc.) should instead operate on the most convenient collection available to the language, no matter whether it is an array, list or some other collection object. --[[User:IanOsgood|IanOsgood]] 17:16, 30 July 2009 (UTC)
Line 23 ⟶ 29:
 
I wonder though whether this site is suitable for providing generic translations or patterns that might be applied in any language to create or emulate a missing construct. For example, implementing static arrays using hashes or strings. ----[[Special:Contributions/66.245.151.131|66.245.151.131]] 04:39, 13 August 2009 (UTC)
 
 
The confusion arises from using the term "array" for different things. This causes ambiguity in the task description. As far as I see it, we can distinguish the following categories:
 
# linear array, i.e. lists (including list of lists)
# associative arrays, (i.e. hash arrays).
# multidimensional arrays (i.e. static array), the number of elements along a certain dimension is fixed. This type of array allows for random access. A matrix is usually a two-dimensional array.
 
If some languages uses the term "array" for some other data structure, it should be added here.
 
Any task description should consider this distinction and make clear which kind of array should be used. Only then we can avoid ambigous task descriptions. [[User:Aschloegl|Aschloegl]] ([[User talk:Aschloegl|talk]]) 15:21, 21 July 2013 (UTC)
 
:For many tasks, this could end up being a distinction without true meaning. Unless the task is specifically about the distinctions you make above then how a task is implemented should be done in the idiomatic way of a language so we can better compare the languages rather than artificially restricting all languages to use the same meaning for "array". If some languages uses a space separated string of the numeric representation of integers as its array on integers then if the task is to store the first ten integers in an array then print the 7'th member of the array, then I think it would be pretty dumb for that languages example to jump through hoops to store ints in any way other than how it does naturally. --[[User:Paddy3118|Paddy3118]] ([[User talk:Paddy3118|talk]]) 09:45, 22 July 2013 (UTC)
 
::I think the term "array" should only be used when talking about arrays. A list is not an array. A hash is not an array. An array is something that allows random access, i.e. you can get a specific item directly using index(es). Note that an array does not need to be multidimensional. A single dimensional array is an array, too.
::Indeed, there is no point to include requirement of some specific data structure in the task description, unless the task is specifically about that data structure. Not all languages have all possible data structures built-in. The task description should describe what is the goal of the task, not how to implement it. --[[User:PauliKL|PauliKL]] ([[User talk:PauliKL|talk]]) 12:58, 1 August 2013 (UTC)
Anonymous user