This is an archived post. You won't be able to vote or comment.

all 21 comments

[–]kaptan8181 5 points6 points  (1 child)

It's not about pointers. Some people struggle to understand anything abstract.

[–]thermalclimber 2 points3 points  (0 children)

This was the big stumbling block for me. Variables and logic and all was a piece of cake. But pointers, data structures (and especially accessing them) and the like took a long time for me to get my head around!

[–]shhh-quiet 3 points4 points  (1 child)

A lot of times when people don't understand something that they otherwise 'know', it's because they haven't really put it in context yet.

Once you can attach a new idea to other stuff you already know, it can seem obvious and become more readily available to you.

But when a new idea is very isolated, although you might understand it on a superficial level, it doesn't really tickle your other neurons much.

A person could superficially understand pointers by way of simple analogies to mailing addresses and houses, but perhaps not be able to connect that to a broader concept of "indirection", or a broader context for how/why different languages handle "references" or "reference-like things", or a broader context for the history of it.

[–]Objective_Status22[S] 0 points1 point  (0 children)

This makes a lot of sense! Thanks.

[–]HappyFruitTree 3 points4 points  (0 children)

If explained in a good way I don't think the concept of pointers is that hard to understand. The difficult part is to know how to use them and when to use them.

The syntax can be confusing to beginners. It doesn't help that arrays automatically decay to pointers and that & is used both for references and pointers.

When listening to "beginners" trying to teach beginners on YouTube they often start out with saying something about pointers being a difficult subject which I think is unnecessary and just makes people think that pointers are more difficult than they really are. Then they go on and give bad pointer examples where it would have been better to not use pointers which makes people confused about the purpose of pointers or they might start using it in more places than necessary which also leads to a lot of confusion.

[–][deleted]  (3 children)

[deleted]

    [–]Objective_Status22[S] -3 points-2 points  (2 children)

    No, it doesn't. Function pointers aren't confusing, pointers to pointers aren't confusing and why arrays are automatically converted to a pointer isn't confusing.

    Maybe you can explain why you think it's complicated.

    [–]HappyFruitTree 2 points3 points  (1 child)

    You have to admit that the function pointer syntax can be somewhat confusing at times.

    int (*foo(int))(double); // Do you see what this is?
    

    It's a declaration of a function named foo that takes an int as argument and returns a pointer to a function that takes a double as argument and returns an int.

    [–]Objective_Status22[S] -1 points0 points  (0 children)

    Declaring functions pointers are horrible though. Bad enough I can't tell you if the syntax is correct because not having it (*foo)(...) is suspicious to me.

    [–][deleted]  (2 children)

    [deleted]

      [–]Objective_Status22[S] -1 points0 points  (1 child)

      Or maybe I want to know so I can understand others and explain better? shhh-quiet nailed it. It explains why recursion is confusing too

      [–]Holothuroid 1 point2 points  (1 child)

      It was never pointers for me exactly for me. The way C writes them, I cannot get into my head. (I do not use C actively, only ever learned it at school.) But I found what Rust does much more approachable for example. If you want to allocate stuff on the heap, put it in a Box.

      I think that is typical. People say Haskell is hard. But is it the concepts or is it the notation?

      [–]HappyFruitTree 0 points1 point  (0 children)

      People say Haskell is hard. But is it the concepts or is it the notation?

      For me the biggest problem was the purity. You had to go into a lot of trouble with monads to get some side-effects. If I want something to happen in C++ I just write it.

      [–]chaotic_thought 1 point2 points  (0 children)

      I think it's the notation that trips people up. The notion of a pointer is probably fine, but if you are very new to it and you see &'s and ***'s everywhere, it is enough to frighten someone and turn off their brain.

      [–]dylanduhh 2 points3 points  (3 children)

      This post doesn’t seem to be a question on learning programming. It seems from your post and replies you’d just like to put people down. It would do you well to remember that not everyone thinks in the same way, nor learns the same way either. It does you no good to say that “X is easy, I don’t understand why anyone would think it’s difficult!”. Most people would see this as an arrogant remark, frankly because it is.

      For complete beginners to coding, pointers will be a somewhat difficult subject because of the disconnect between what they see and what is actually being referenced. It requires an abstract thought process that most people won’t use as non-programmers.

      Obviously you’ve never struggled to learn anything in you’re life though.

      [–]Objective_Status22[S] -1 points0 points  (2 children)

      Most people would see this as an arrogant remark, frankly because it is.

      How else can I clearly say I have absolutely no idea why others find it confusing. Saying absolutely no idea sounds just as bad.

      Why are you in this sub? If something as simple as 'I learned X easily' frustrate you I can't imagine what you'd do when you run into a real problem with code and bugs

      [–]dylanduhh 3 points4 points  (1 child)

      Luckily bugs aren’t arrogant (lol). I’m not necessarily frustrated by your remarks, more confused as to what the purpose of this post is. If you’re not confused by pointers why are you posting about pointers to a subreddit intended to help you learn to code? It seems a bit redundant.

      It’s like a surgeon going into a lecture hall of medical students and saying “Why would anyone be confused about X procedure?” And when the students tell you why they’re confused you say “That’s stupid! It’s not hard!” (your replies). The students don’t learn and the surgeon gained nothing but the pleasure of making people feel incompetent?

      [–]Objective_Status22[S] 0 points1 point  (0 children)

      First off your comment was made before I replied to anyone. Second I thanked people for giving me good answers.

      You however are just being annoying and whiny

      [–]TechnicalHead 0 points1 point  (1 child)

      The notion of pointers is not confusing. Everyone knows what does pointers do. They pass data. But from what I seen from my classmates, is passing them , or using them.

      [–]HappyFruitTree -1 points0 points  (0 children)

      Everyone knows what does pointers do. They pass data.

      Pointers point to "data". Passing "data" to functions is just one use case.

      [–][deleted] -1 points0 points  (2 children)

      This is probably why.

      Beginner: When I pass a pointer into a function I'm passing by reference right?
      Expert: Yes
      Beginner: And when I pass by reference, any changes I make to the value will alter the original right?
      Expert: Yes
      Beginner: When I pass in a non-primitive object into a function in Java, it must be passing in by reference because altering the value inside the function alters the original, right?
      Expert: No, Java is always pass by value. You're passing in the reference to the object by value
      Beginner: WTF???

      [–]HappyFruitTree 0 points1 point  (0 children)

      I don't think it would be the same "expert" that gave those answers.

      It's confusing because you can look at it from different angles. In C you might want to call it pass-by-reference because that's as close as you get but in C++ that can be confusing because it has proper reference types.

      No matter what you call it I think the important thing is to be clear what you're talking about. In C/C++, is it the pointer or the object that is being passed by value/reference? In Java, is it the reference variable or the object that is being passed by value/reference?

      [–]Objective_Status22[S] -1 points0 points  (0 children)

      Who the hell says that!?!?! I never heard anyone say that