[Year 12 SofDev] Records and Arrays

Steven Bird sb at csse.unimelb.edu.au
Thu Aug 19 21:28:31 EST 2010


On 19 August 2010 20:53, Janson, Adrian A <
janson.adrian.a at edumail.vic.gov.au> wrote:
> A one dimensional (or 1D) array is a data structure in which variables are
grouped together under the same name...

I see a couple of problems with this definition.  First, an array can group
together things which are not variables, i.e. literals, e.g. in Python:

>>> foo = [1, 1, 2, 3, 5, 8, 13, 21]
>>> bar = ["no", "variables", "here!"]

Second, an array is an array even if it doesn't have a name, e.g. in Python:

>>> my_function(["I", "don't", "have", "a", "name"])
>>> ["indexing", "a", "literal", "array"][2]

> A record is a structure that can be used to group together variables for a
particular purpose.

This definitions shares the first problem above, but it also brings in
something extraneous: "for a particular purpose".  Surely any data structure
serves some particular purpose intended for it by a programmer.

> Indexing the elements of a record is often done via an identifier which is
declared at the same time as the record.

This is true when the record is implemented as an associative array, but not
when it is represented as a tuple.  E.g. in Python:

>>> array_of_tuples = [(1441412050, 'Alice in Wonderland', 'Lewis Carroll'),
...     (1441412341, 'Through the Looking Glass', 'Lewis Carroll')]
>>> print array_of_tuples[1][2]
Lewis Carroll

Here we accessed an element of a record using an integer.  But you're
probably ok here since you said "often", and I agree with that.

-Steven Bird
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.edulists.com.au/pipermail/sofdev/attachments/20100819/9e815206/attachment.html 


More information about the sofdev mailing list