IWETHEY v. 0.3.0 | TODO
1,095 registered users | 0 active users | 0 LpH | Statistics
Login | Create New User
IWETHEY Banner

Welcome to IWETHEY!

New Why pointers are so hard.
I think I have finally realized why pointers are so hard for most people to understand. People easily grasp the concept of record/structure, but when it comes to pointers as members, they rebell. I think the reason is that most modern languages allow you to access the pointed object as if it were a member of the member of the structure. And this is against a very deep principle: "A part must be smaller than the whole". So when you see something like

current = current->next


don't be surprized when some people balk at it.
New Then find another analogy
What you are describing is someone who thinks in terms of structures involving pointers as nested data structures balking at manipulations that don't quite fit that model. But does it improve if they have a different model?

There is no shortage of other possible mental models. One is a business answering the phone. Each person you talk to knows a certain amount of stuff, and can transfer you to others. The stuff they know, and the knowledge of who to transfer you to, is the structure you are looking at. And most organizations are going to be structured into fairly reasonable hierarchies.

But when you do something like:

current = current->next;

that is just like your saying on the phone, "OK Mary, I think that wraps up what we need to do, can you transfer me to whoever is next?" And she says, "That would be Bob, hold on for a second..."

I haven't tried it in trying to teach people, but I would think that a concrete image like that might help a lot of otherwise easily-confused people.

Cheers,
Ben
New Indeed
I am not saying that this block is impossible to remove, I am just saying that that's the most common block.
New It probably has something to do with the language.
When learning C, you have to grasp pointers quite early. There is really no avoiding it. You can put it off a little but longer in C++, but not indefinitely. OTOH, languages like PHP and Icon have built-in data structures that are less like high-level assembler and require more runtime - e.g. lists and tables - and so understanding pointers is a distinctly advanced concept many programmers do not need.

Wade.

"All around me are nothing but fakes
Come with me on the biggest fake of all!"

New I think it's because they haven't learned the basics yet.
current=current->next; isn't difficult to learn...


provided you understand you can do this
x = x + 1;

The original x (right-hand side) is lost - just like the original current is lost.

I will agree most people have trouble with pointers however. I ususally use an address/little box metaphor. You're defining a space (pointer space). You can assign to it, add it, reassign it, set it to NULL, etc.

Now, if you want to access what's at that space, then use the * and ->.

New Different students may need different analogies
For example, somebody with a table-head (or plenty of table experience) might grok the idea that a pointer is simply like a record-ID to another record in the table (foriegn key). Unlike RAM addresses, ID's *are* something that you actually see in table-land. (Some OO fans say this is bad, but that is another long message-right-shifting story).

________________
oop.ismad.com
New For some, none may work.
New Think of it this way
it is sort of like using a virtual address, not a real address, but a placeholder to the next piece of data in the chain of data you are working on.

You know, it "points" to the next piece of data on the list, hence the name "pointer".

"Before Christmas it is 'Ho ho ho', after Christmas it is 'Owe owe owe'" - Santa Norm
New I like to think of it as
a forwarding address.

You go there, but what you want isn't there, there's just this note telling you what you want is really over there. Changing a pointer is like updating the forwarding address.

Worked for me for awhile. Now its just second nature.
New Recursion?
Another way one can think of pointers is as a poor man's version of recursive data structures. For example, in a language like Haskell, you'd express the structure of a binary tree as:

data Tree a = Nil | Node a (Tree a) (Tree a)

...making the recursive nature of the data structure a little more obvious. Languages without the notion of recursive data types have been known to use pointers to do perform similar chores - where the record contains a pointer to the same type as the containing record.

For myself, pointers came pretty natural to the extent that I started out programming in assembly language well before moving on to a HLL. I tend to view them in terms of Address registers - but that may not be helpful to those who don't have that low level exposure. Becomes real obvious when you set the pointer in the high level language to a memory space that is hardware i/o - things like using an array to draw an image on a display by simply setting the pointer to the appropriate memory address.
     Why pointers are so hard. - (Arkadiy) - (9)
         Then find another analogy - (ben_tilly) - (5)
             Indeed - (Arkadiy) - (1)
                 It probably has something to do with the language. - (static)
             I think it's because they haven't learned the basics yet. - (Simon_Jester)
             Different students may need different analogies - (tablizer) - (1)
                 For some, none may work. -NT - (ben_tilly)
         Think of it this way - (nking) - (1)
             I like to think of it as - (tuberculosis)
         Recursion? - (ChrisR)

We bought the office.
67 ms