News for hackers. Stuff that matters.
Re:Hopefully more controversial programming opinions by alexchamberlain on Thursday August 30, 2012 @03:55AM (#4453537)
I've never understood what's confusing about pointers...
Re:Hopefully more controversial programming opinions by mkopinsky on Thursday August 30, 2012 @04:11AM (#4453571)
1) Indirection. Pointers require thinking in a few steps. Indirection is hard. It is a vital skill in any kind of programming (or especially debugging), but it does not come naturally to people who've only ever had to deal with the concrete.

2) Early on, you learn that ints and chars and floats and some_structs are fundamentally different data types. Then suddenly you're told that int%s, char%s, float%s, some_struct%s, and even void%s are fundamentally the same. Huh?

3) The fact that C uses % both to create a pointer and to dereference. These are conflicting meanings, and the unrelatedness of those two concepts is not sufficiently explained.

EDIT: Silly HN parser. I now replaced asterisks with %s.

Re:Hopefully more controversial programming opinions by alexchamberlain on Thursday August 30, 2012 @04:23AM (#4453601)
3) That make's sense. For example...

    int *i;
means "When you dereference i, you get an int."
Re:Hopefully more controversial programming opinions by mkopinsky on Thursday August 30, 2012 @04:37AM (#4453648)
When I see

   int a;
I read "create an integer variable called a".

    int *i;
means, "create a variable that when dereferenced, points to an integer".

Makes sense once you understand it, but I can definitely understand how a beginner would find it confusing.

Re:Hopefully more controversial programming opinions by alexchamberlain on Thursday August 30, 2012 @04:47AM (#4453674)
It may be a problem with the teaching though, rather than the subject matter itself. I understand why it takes a little bit of thinking to get used to, but not why it is fundamentally hard.

Now, algorithms can be difficult to understand and many of them use pointers... Do some people confuse the 2?

Re:Hopefully more controversial programming opinions by mkopinsky on Thursday August 30, 2012 @05:00AM (#4453716)
I don't think the difficulty is fundamental, and I don't think anyone here claimed that it was. But it is initially challenging nonetheless.

To tie this back in to the beginning of the thread, being able to understand indirection (such as in pointers and algorithms) is a far more important skill than understanding OOP.

Re:Hopefully more controversial programming opinions by InclinedPlane on Thursday August 30, 2012 @04:19AM (#4453587)
Re:Hopefully more controversial programming opinions by d--b on Thursday August 30, 2012 @10:29AM (#4454793)
It's the abstraction that's difficult to get in the first place. In Basic, a variable represents at the same time the data and its memory address, the two concepts are not separated. When you introduce pointers, you split that concept in two: address and data, and to complicate you say address is some form of data. In Basic, the variables are the memory. Each variable you manipulate is equivalent to a piece of memory you can store things in or get things out. With pointers, you loose that equivalence: memory becomes invisible through the code. I can have a memory block that exists in my memory that is no longer pointed by any variable. This means that you get a separation between the way memory is and the way the code looks like. What is difficult when learning pointers is to get that extra level of abstraction: you have to look at the code as an access route to the memory, not as the memory itself.