Can anyone explain to me why almost any basic concept of programming is no problem for me to understand, yet I have such a hard time grasping object-orientation (objects, methods, classes, messaging, …) and, worse, pointers?
Countless efforts from peers (including my brother) to explain it haven’t helped. Ugh!
Others' Thoughts
Comment on November 16th, 2005 at 12:54 am
Object-orientated looks at objects. So look at things around you when doing object-oriented programming. Especially look for things that define classes, like chalkboards and desks.
As far as pointers go, there is one on your screen that does everything you want it to. That should be enough…
Comment on November 16th, 2005 at 1:09 am
I understand what object-oriented programming is. I don’t understand how to properly use it.
And very funny about the pointers remark. I am not talking about the mouse pointer, silly.
Comment on November 16th, 2005 at 3:20 am
Don’t feel too bad about pointers and OOP… C and C++ are ridiculously obnoxious about how complicated they make the concepts, and they’re a large part of what scared me away from programming back in 2000.
If I were to pick up trying to program in C++ again today, I’d likely still be rather hopelessly lost because it’s been 5 years since I’ve used it, but I’d probably have a firmer grasp of OOP and pointers from dabbling with the concepts in PHP, which handles them in a fairly simple manner. Still, true 100% OOP programming escapes me, so I’m probably not the best person to try and give you (with no pun intended, I swear) pointers on the subject.
Comment on November 16th, 2005 at 8:53 am
The truth is, no one can be told what OOP is. You have to see it for yourself. – Morpheus.
Seriously, though. I know the last thing I would want, had I posted this, would be a lot of guys telling me the answers that I’d already heard before. So, I’ll just say this: I understand.
If you want to take another stab at figuring it out, let me know, and I’ll do my best to help.
Comment on November 16th, 2005 at 12:20 pm
I have no idea what pointers are. Does VB. NET use them?
As far as OO goes, I don’t see what you don’t see about how to use it. Can you be more specific? Maybe VB.NET making OO incredibly effortless and powerful to use have made me not realize how complicated it is.
shrug
Comment on November 16th, 2005 at 1:33 pm
No. A few languages let you use them, PHP for example, but there’s only one language (we know who you are) that actually makes you use them — C.
While .NET is obviously heavily object-oriented, VB.NET itself, as far as I can tell, is not that strictly an object-oriented language (not that I ever used it that much).
Comment on November 16th, 2005 at 9:39 pm
moiety has no idea what a pointer is?! At first that really surprised me, but I guess it kind of makes sense.
Hmm, the one thing I can think of you might recognize is passing things to a function “ByVal” or “ByRef”, which I think I remember from VB.NET, but it could have been just VB. This mirrors a use of pointers in C. Passing a pointer to a function would be like passing something “ByRef”, which lets you modify the original thing, rather than a copy.
chucker:
A pointer is an address to a place in memory that a certain type of value (say an integer) is stored.
The variable a is an integer with the value set to 1, the variable is b is not an integer but an address to an integer somewhere in memory. It starts out with a NULL or 0 value.
You can get an address of any variable by using the & symbol. So the memory address of where the variable a is in memory can be retrieved by &a. The variable b and &a are both addresses, so you could…
Now the variable b is set to an address, the address of where the variable a is stored in memory. To get the value of what the address b is pointing at, you use the . So now, b is the same as a.
There, that’s the very basic idea of pointers. There are many more advanced ideas, plus all the uses for them. But that’s all for now.
(Now I hope that all my tags come out right when I hit submit … )
Comment on November 16th, 2005 at 9:48 pm
I’m sorry, I should have made myself more clear. I know what a pointer is. I know what it does. And while I really appreciate your examples, I understood them even without the explanations. What I don’t know is: it seems such a crucial concept to C, yet many languages appear to get along fine without it. Why’s that? What huge advantage do pointers give? Are they a necessity to accomplish something?
And no, the tags didn’t quite come out right, but that’s quite alright, I make such mistakes myself often enough.
Comment on November 16th, 2005 at 10:11 pm
Well, then the explanation can be for moiety, and any others who don’t know what pointers are.
Because most languages automatically handle everything as pointers for you.
In Java, I believe that when you pass a variable to a function, it automatically passes it by reference, which is passing its address instead of a copy of the value. But it doesn’t let on that what is being passed is a pointer, you can use it as if it were a regular variable.
C++ added passing by reference so you could do the same kind of thing without having to deal quite as directly with pointers. (although I’ve had some fun passing pointers by reference in recursive functions in C++. :D)
And Ruby, everything is basically a pointer. When you are using variables and passing them around, it’s passing an address around rather than the value, and the address can be used normally to access the value.
C just allows you to very distinctly control addresses and pointers. C is very low level and tries to let you control things that way. Other languages, especially new ones, take care of the pointers behind the scenes. It’s not that they don’t get along without them, they are just not making you worry about whether you are passing a copy of a value or an address of a value and properly treating something as an address or a value.
Comment on November 16th, 2005 at 10:16 pm
That’s what I figured it was (that some languages do things automatically that others don’t)). Good to know, thanks.
I’m sure the flexibility C offers has its advantages (especially performance-wise), but I get the feeling it just isn’t for me.
Comment on November 17th, 2005 at 4:46 pm
Pointers certainly have their performance advantages. Consider the following code fragment (size is some large constant):
Now, compare it to this:
int *aptr, *bptr, *cptr, *dptr; for (aptr = a, bptr = b, cptr = c, dptr = d; a_ptr Assuming that the value of c + size is computed only once (since it is essentially a constant), the second example will be more efficient, as less addressing calculations have to be performed.
Comment on November 17th, 2005 at 4:50 pm
Hmm, I think I broke your website - again. Sorry. I must’ve accidentally opened a second <code> tag instead of closing the first one (and I probably made the same mistake twice)…
A preview function would be nice.
Comment on November 17th, 2005 at 5:11 pm
I tried to fix your comment but I think I lost some of the code in the progress. It doesn’t really make a lot of sense. I think you were using < and > signs without encoding them.
And why do you and Tay insist on using the
codeelement for blocks of code? It’s inline, not block.Comment on November 17th, 2005 at 5:35 pm
Ah yes, that must’ve been it. This is what it should have been:
int i; for (i = 0; i < size; i++) { c[i] = a[i] + b[i]; d[i] = a[i] - b[i]; } And the second part:
int *aptr, *bptr, *cptr, *dptr; for (aptr = a, bptr = b, cptr = c, dptr = d; aptr < a + size; aptr++, bptr++, cptr++, dptr++) { *cptr = *aptr + *bptr; *dptr = *aptr - *b_ptr; } Oh, and I use the <code> tag because it presumably preserves indentation.
Comment on November 17th, 2005 at 6:36 pm
Not only does
codenot preserve indentation (that’s whatpre— as in “pre-formatted” does); it also utterly fails to render.I fixed your comment.
Comment on December 19th, 2005 at 6:33 pm
“While .NET is obviously heavily object-oriented, VB.NET itself, as far as I can tell, is not that strictly an object-oriented language (not that I ever used it that much).”
VB.NET == C# with a modified syntax
In the age of the MS.CLR, the distinction between languages can fall down to just syntax… At least between these two. There are tools that automatically transcribe VB.NET C#, and usually, the code runs with just minor, if any, modification. (Unless your app is super-complex.)
That said — why would it not be an OO language? Whenever I do something as simple as open/display a Windows Form, I use OO, because I need to create a new instance of that specific form class… And the whole Model component of the MVC triad is loaded with classes that you create various instances of and re-use and…
…yeah. Fear not, VB.NET is OO. But I guess the thing is it’s only as OO as you’d like it to be, to an extent. But componentization like this saves so much time (and code!), so why would anyone not use it?
Comment on December 19th, 2005 at 7:18 pm
I have never disputed that.
Its primitive variables are non-objects, just like in most languages. There is no such distinction in Ruby.
Well, GUIs are (almost) always OOP anyway.
Your Own Thoughts
I'd love to hear your input. Just try to stick to a few rules:
Before you comment for the first time (or, after you have deleted cookies), you will have to answer a little challenge to prove that you are not a spammer.
Comments are written in Markdown.