I was going to write an article about how pointers aren't confusing
-
Kris Lantz wrote:
Time for coffee...
Why did you do that? The only thing you should do before drinking coffee is making coffee. Any other action is futile, except you won't be assimilated. :laugh:
Even better -- visit your favorite coffee shop. :-)
-
On the weekends, coffee enjoyment is top of the list. The weekdays are a bit more chaotic, and coffee may not be had until about a half hour after getting to work. :^)
Kris Lantz wrote:
The weekdays are a bit more chaotic, and coffee may not be had until about a half hour after getting to work
Make coffee at home and bring a travel mug? All jokes aside, sipping my coffee while reading morning emails helps me settle my mind and prepare for the work day. For me there is a settling effect in sipping coffee, even during an ugly commute. I normally work early hours, so the commute isn't as ugly in the AM as the PM, and the folks in the office at my arrival time are doing the same as me, so there is not usually immediate chaos. [Anyone who arrives to immediate chaos appreciates this.] However -- these days, going to work consists of getting up, starting a pot of coffee, and then logging in. My commute is 35 steps instead of 34 miles. I really appreciate WFH!!!
-
Until I realized in the process of trying to explain them that they probably are. Just because I find something intuitive doesn't mean I can make it intuitive to others. :doh: The secret with pointers is to enjoy the freedom they bring you rather than fearing the danger they present. Aside from that, the rest is details.
Real programmers use butterflies
the C abstract machine there is no problem with pointers if you look straight at them. the problem is when somebody tries to wrap them in some obscured "politically correct" story that doesn't hurt a chipmunk if you step on it. i know this line is confusing, but Pascal was my first programing language and when the time came to grow up and use pointers normally i reached for a Pascal programming book... well, that book in it's chapter of pointers had everything else, about lists, about binary trees... but i could not tell what pointers are. i mean, the person who wrote that book constantly repeated how pointers are really useful although you should avoid to use them as much as possible... he doesn't know about pointers. then i read a chapter about pointers from a C tutorial and everything became crystal clear. there was i happy and using pointers in Pascal. the same thing was with win32 programming. you can not learn it from a Delphi book, you need a C book for that. but you can sure as hell do that in Pascal as good (or better) as in C if you learn the right way. pointers are a fundamental thing. the 8086 processor has a few general purpose registers and about the same number of Index registers. out of this bunch SI and DI are your pointers. and i bet you will understand pointers even better if you learn assembly than C, but C is good enough.
-
the C abstract machine there is no problem with pointers if you look straight at them. the problem is when somebody tries to wrap them in some obscured "politically correct" story that doesn't hurt a chipmunk if you step on it. i know this line is confusing, but Pascal was my first programing language and when the time came to grow up and use pointers normally i reached for a Pascal programming book... well, that book in it's chapter of pointers had everything else, about lists, about binary trees... but i could not tell what pointers are. i mean, the person who wrote that book constantly repeated how pointers are really useful although you should avoid to use them as much as possible... he doesn't know about pointers. then i read a chapter about pointers from a C tutorial and everything became crystal clear. there was i happy and using pointers in Pascal. the same thing was with win32 programming. you can not learn it from a Delphi book, you need a C book for that. but you can sure as hell do that in Pascal as good (or better) as in C if you learn the right way. pointers are a fundamental thing. the 8086 processor has a few general purpose registers and about the same number of Index registers. out of this bunch SI and DI are your pointers. and i bet you will understand pointers even better if you learn assembly than C, but C is good enough.
I first used pointers in asm, because it was the first thing other than basic i could really write code in for the 6502. I learned C later. I'm fine with them. it seems many other people aren't, hence the idea for the article. :)
Real programmers use butterflies
-
I think that's a common trap. It doesn't help that misusing them causes faults because I think that makes them intimidating but all a fault is is an unhandled exception. Fear is a huge stumbling block to growth. It doesn't help that I've seen lots of articles (not necessarily here) rag on pointers and state that they're scary in so many words, probably from authors that never got comfortable with them themselves. A lot of times it's no different than accessing an array.
Real programmers use butterflies
> probably from authors that never got comfortable with them themselves. or maybe got paid to support some language that is safe (secure). security or the opposite of it, fear, sells a lot in modern times. i don't know what is it these days, but everyone is trying to jump on you with a zealot yelling that you are doing something wrong. that you're incompetent. loser. that they are going to open your eyes with this new way, new programming language, new framework... ok, i get that. these are lamer times. instead of friendship there is mostly ridicule, which makes everybody look bad in the eye of the beholder. although new or old things have interesting ideas, nothing is black and white. "if somebody is selling you a technique in convincing you that there is something that you should do, they're focusing on the benefits and they are either gonna be downplaying the drawbacks or they'll be ignoring them completely" - Jonathan Blow on Software Quality at the CSUA GM2
-
I first used pointers in asm, because it was the first thing other than basic i could really write code in for the 6502. I learned C later. I'm fine with them. it seems many other people aren't, hence the idea for the article. :)
Real programmers use butterflies
yeah, i was on the 6502 too. the most close to pointers out of the top of my head was this addressing mode like: lda ($fb),y or lda ($fb,x) hell, i don't even remember was there a comma or a dot in front of the index register. much less how these two modes were called.
-
I first used pointers in asm, because it was the first thing other than basic i could really write code in for the 6502. I learned C later. I'm fine with them. it seems many other people aren't, hence the idea for the article. :)
Real programmers use butterflies
> it seems many other people aren't, hence the idea for the article. than it's just a matter of time. just do it!
-
yeah, i was on the 6502 too. the most close to pointers out of the top of my head was this addressing mode like: lda ($fb),y or lda ($fb,x) hell, i don't even remember was there a comma or a dot in front of the index register. much less how these two modes were called.
YAY the bad old days!
Real programmers use butterflies
-
What's so confusing about them? They point to a memory location. Think of an address as an index into a big array of bytes. No big. =)
Real programmers use butterflies
Honey, that is exactly why they are confusing! The problem is English and the really sloppy way programmers use English! Pointers do not actually "point" to a memory location. The fact that you can get to a data element in memory and that method that can be manipulated as if it were a number is a *compiler specific concept* in the C family of languages. And an incredibly stupid idea that creates tons of security vulnerabilities. NEVER, EVER use a pointer as if it were a number. ALWAYS use it as an abstract data type and you will avoid 99.9% of pointer type defects in your code. I am mentoring a young woman who is taking her first real programming class (Python *DOES NOT* count). --------------- Here is what I told her: Anyone who has ever written in a "proper" language like Pascal, Modula, PLM-86, or Ada or who studied actual Computer Science will tell you that a "pointer" is an abstract data type that is nothing more than a handle to some object in your program. There are *NO* operations defined for a pointer other than connection to some object, referencing an object (either an actual object in C++, C#, Ada, etc. or a struct or intrinsic in C) or copying a pointer to another pointer of the same type. You can literally use a "pointer" as a handle to carry data around in your program from one place to another. In some languages we use the word "reference" as a synonym for a pointer. I also gave her a physical example of how pointers can be used in linked lists. ---------------- Kernighan and Ritchie (bless their hearts) improperly called a data type by the CS name "pointer" when they should have named it an "address". They ARE NOT the same thing. In modern computers, that is absolutely the case because the "address" you get is just a virtual mapping of an actual address to some other thing that just happens to be a number (but you have to understand hardware to understand why that is). K&R (or some folks after them) also screwed up the keyword "static" which has two *completely different* meanings depending on context. The list of things screwed up in C is a long one! It is why the MISRA standard is necessary. C was just readable assembly language for the PDP-11 computer which got moved over time to other computers. Because you are forced on very small computers to play tricks in C/assembler in order to save data and code space, C has some really egregious history of confusing pointers with addresses and the fact that you can actually see a *real* computer underneath the virtu
-
Until I realized in the process of trying to explain them that they probably are. Just because I find something intuitive doesn't mean I can make it intuitive to others. :doh: The secret with pointers is to enjoy the freedom they bring you rather than fearing the danger they present. Aside from that, the rest is details.
Real programmers use butterflies
I think I would agree that pointers are quite intuitive, but I still prefer the way Java, for example, takes away the need to deal with them directly, though one still ought to understand what is happening under the hood. Constructing a linked list in Java takes away the need to think about pointers at all (so be careful those who use this as an interview Q). I like languages which allow me to spend more cognition on the business logic rather than its implementation. Also, modern compilers can implement code better than most (if not all) of us humans can. That said, there is something aesthetic about pointers, more so when you deal with memory management in assembly langauge. I quite like the fact that C lets you get to grips with these lower level devices, though in my work it's more of an aesthetic curiosity than a necessity to know these things.
-
I think I would agree that pointers are quite intuitive, but I still prefer the way Java, for example, takes away the need to deal with them directly, though one still ought to understand what is happening under the hood. Constructing a linked list in Java takes away the need to think about pointers at all (so be careful those who use this as an interview Q). I like languages which allow me to spend more cognition on the business logic rather than its implementation. Also, modern compilers can implement code better than most (if not all) of us humans can. That said, there is something aesthetic about pointers, more so when you deal with memory management in assembly langauge. I quite like the fact that C lets you get to grips with these lower level devices, though in my work it's more of an aesthetic curiosity than a necessity to know these things.
I tend to agree ... until I don't. That is to say, I appreciate not having to deal with them until I'm given occasion to miss them. Sometimes - and I find quite often in C and C++, there's a much more elegant and/or efficient solution to be had using pointers than working without them. I tend to like the STL because it takes away the need for pointers, but doesn't prevent you from using them.
Real programmers use butterflies
-
I tend to agree ... until I don't. That is to say, I appreciate not having to deal with them until I'm given occasion to miss them. Sometimes - and I find quite often in C and C++, there's a much more elegant and/or efficient solution to be had using pointers than working without them. I tend to like the STL because it takes away the need for pointers, but doesn't prevent you from using them.
Real programmers use butterflies