|The Trick Of The Mind - Representation|
|Written by Mike James|
|Monday, 18 July 2022|
Page 3 of 3
The Record Represented
How do you represent a record?
The answer is that it is very similar to an array but instead of being organized by a number it is organized by field name. Such an organization should be called a record, but in most computer languages it is called a struct – short for structure. For example:
struct myAddress name: “mike” address: “1 FORTRAN Avenue” Telephone: 1234
defines a struct as a representation of an address record. To get to particular fields the most common convention is to use a dot notation or a qualified name.
has the value mike and
has the value 1234.
Records or structs are most often used in programs that are about business. Scientific applications most often use arrays. Today most programming languages have arrays and structs, but in the early days it was often one or the other. For example, FORTRAN had arrays but no structs or records until much later – yet another example of the “two cultures”.
Nesting Data Structures
The array and the struct are the two simplest examples of data structures. We start from the basic idea of a variable and work our way up, representing ever more complex things using nothing but numbers and what we have already defined.
An array is a numbered list of items and a struct is a record of items accessed by field name. However, a field in a struct can be an array and we have already used this fact when we stored a “mike”, a string or character array, in myAddress.name. That is the field myAddress.name is a string, not just a simple value. This is a general principle. Each time a new data structure is invented to represent something in the external world it can usually be combined with existing data structures to do even more.
For example, an array can have elements that are arrays. This is a doubly numbered list or a two-dimensional array. An array can also have elements that are arrays of characters. This is more usually called an array of strings or string array. In this case we really do have something that is more like a numbered list because each element is a piece of text.
A struct can have fields that are arrays and arrays can have elements that are structs. What does this mean? An array of structs looks like a numbered list of records – an address book of sorts. In this case you could find the address of a particular entry by knowing its number in the list.
would the name field of the fifth address in the list. You can see how things start to look complicated even though the basic idea is very simple.
Things do become more sophisticated as we continue to develop the idea of finding representations for external world things. For example, the array of structs or records easily evolves into the idea of a database – a set of multiple lists of records that are related to one another in some way. A database might have a list of the names and addresses of the members of a club, a list of names and employment records of company employees, or a list of the prices and stock levels of inventory items to give only a few obvious examples.
The Data Determines The Program
At first look it seems that the problem of data representation is isolated from the problem of creating programs – but it isn’t. Data and how you work with it are very much intertwined. For example, if you have an array representing your data then the chances are you will need to examine each element or a subset of elements and this means that you are bound to write a loop. Arrays and loops go together in a very natural way, see the next chapter.
Similarly, though less obviously, other data structures determine what you are most likely to do with them and hence the form of the program that processes them. This idea has been elevated to the status of a programming method – search the Internet for Jackson Structured Programming – but these ideas are mostly out of fashion now.
What is very much in fashion is the idea that the data and its representation is more important than the program. A data representation should be active and incorporate what you most want to do with it. For example, a list of things should include a way of sorting the list and finding a particular entry in the list. Normally you would think of these actions as being part of a more general program, but in this view they should be integral parts of the data. When data and actions become intertwined in this way the result is usually called an “object” and the programming approach is called "object-oriented programming“, see Chapter 12.
Objects are data representations that know how to do things, i.e. perform actions that are appropriate for the data. This is a very sophisticated idea and it is currently the accepted way to program all but the simplest of things. As discussed in Chapter 12, in this world view, data is more important than lists of instructions.
As already stated, the basic idea is to find representations of real world things in terms of nothing but numbers. Once we have the idea of mapping characters to character codes we can process text and everything else just seems to follow. There are lots of examples of sophisticated data structures that represent less common things from the real world – hierarchies or trees, for example – but the basic idea is the same.
You might be thinking that this idea of finding representations is unique to programming, but it isn’t. Computers work in binary, but for most of the time you can ignore this. Computers work with symbols that are represented in binary, but you can concentrate on the manipulation of the symbols.
This is much the same as what we do with natural language and natural thinking. We have a limited number of symbols available to use – usually an alphabet and we put these together to make words, and then sentences and then paragraphs and so on. Language is a symbolic representation of the world and often the solution to a problem requires us to find a better, or different, representation of something. If the something is completely new then you might need a completely new way of representing it, usually involving the symbols of mathematics.
The art of building symbolic representations is a key part of problem solving and thinking in general.
The Trick Of The Mind - Programming & ComputationalThought
Buy Now From Amazon
or email your comment to: firstname.lastname@example.org
|Last Updated ( Monday, 18 July 2022 )|