[Year 12 SofDev] Records and Arrays

Laurie Savage savage.john.l at edumail.vic.gov.au
Thu Aug 19 08:39:42 EST 2010


Well yes, and no. Thanks for the very clear description of a record which IS
an array (is ISBN an integer or a string? PHP will treat it contextually)!
However this does not take away from the fact that some major modern
languages are not strongly typed and so the study guide distinction does not
apply and this disadvantages students working in those languages.

 

Laurie

 

From: sofdev-bounces at edulists.com.au [mailto:sofdev-bounces at edulists.com.au]
On Behalf Of Steven Bird
Sent: Wednesday, 18 August 2010 8:58 PM
To: Year 12 Software Development Teachers' Mailing List
Subject: Re: [Year 12 SofDev] Records and Arrays

 

The following might help you to distinguish these concepts.

Consider any kind of real world entity, e.g. a student, a school, a book, a
patient, etc.  Now think about its attributes.  For a book this might be
title, author, year, isbn, price...  When we model such an entity using a
computer, we specify a set of attributes.  This is a "record".  It is just a
collection of attributes describing an entity.

A record could be stored on disk (e.g. as a row of a relational database
table, or as a row of a CSV file), or represented in volatile memory in a
data structure in a running program.  Perhaps the most common data type used
for representing a record is an "associative array" ("hash" in Perl;
"dictionary" in Python; "array" (!) in PHP, "map" in C++); some languages
support a "tuple" type which is also appropriate for representing records.
However, at one level these details don't matter.  What's important is just
that we have a set of attributes.

Now consider any collection of entities of the same type, e.g. students,
schools, books, patients, etc.  When we model these in a computer, we
specify a collection of like entities.  This is just a set or list of
entities.

This list could be stored on disk (e.g. as a relational table, or a CSV
file), or represented in a running program.  The most common data type is an
"array", and that's what it is called in most languages (but it is "list" in
Python).  Some languages encourage you to define array elements to be all of
the same type, but not all.  In general, I think this is a good practice.

PHP blurs the distinction between records and arrays.  However, a programmer
can use PHP in such a way to keep them quite distinct:

my_record1 = array('isbn'=>1441412050, 'title'=>'Alice in Wonderland',
'author'=>'Lewis Carroll');






my_record2 = array('isbn'=>1441412050, 'title'=>'Through the Looking Glass',
'author'=>'Lewis Carroll');





my_array = array(my_record1, my_record2);












my_record1['isbn'];   /* access a record's attribute by name */  


my_array[1];          /* access an array's element by index */

I hope this helps!

--
Steven Bird
http://stevenbird.me/


Important - This email and any attachments may be confidential. If received in error, please contact us and delete all copies. Before opening or using attachments check them for viruses and defects. Regardless of any loss, damage or consequence, whether caused by the negligence of the sender or not, resulting directly or indirectly from the use of any attached files our liability is limited to resupplying any affected attachments. Any representations or opinions expressed are those of the individual sender, and not necessarily those of the Department of Education and Early Childhood Development.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.edulists.com.au/pipermail/sofdev/attachments/20100819/bde12a1f/attachment.html 


More information about the sofdev mailing list