vesuvius wrote:
Not even finished reading this thread but I reciprocate.
People are just too scared of pointers though, its the syntax thats abstruse.
Pointers are nice, quick, easy, and flexible (assuming you understand them at all) until you realize that you're returning to 15 year old code that heavily uses void pointers and never well documented what the expected object was or if the expected object was a pointer to the object or a pointer to the pointer of an object. Quite frankly pointers can reduce readability of code drastically.
Now I do like pointers and there are uses for them, I especially like typed pointers and typesafe pointers. However there is a time and place for things, and quite frankly pointers were overused and were used when nothing better was available.
Do you remember the old fashioned arrays, which were pointers to blocks of memory. You're referencing wouldn't be by index like a[i] it would be more like a[i * sizeof(int)], woe to you if you got the type or size wrong as you'd get back or write the wrong data potentially even overwriting someone else's memory.
Or even worse was this method of iterating through an array:
a += 4; // or whatever other hard-coded size of the object
looking at just that is meaningless, you'd have to realize a is a address in memory and that by adding 4 to it you're advancing what is being addressed by 4 bytes to address the next element of the array.
There's many good reasons to prevent direct access to a memory location, especially in managed code where GC is performed that may move your memory around. It's also useful in preventing malicious attemps at abusing pointers to start reading someone else's data.
C# and Java still have pointers, you just don't have direct access to them like you would in other languages. This concept is convoluted further with variations in termanology. Reference, Pointer, Method, Function, etc serve to differenciate but what is often left behind in teaching it is that connection that Method is equivilent to Function and that Reference is a (protected) Pointer. This is what needs to be addressed by education not saying that learning a specific language as the base language for course work makes students ignorant.