Hacker News new | past | comments | ask | show | jobs | submit login
Ask HN: Why do students have a hard time understanding pointer arithmetic?
2 points by noob_eng on April 3, 2023 | hide | past | favorite | 2 comments
We often hear that C is not a good language to get started in programming. Most schools have moved onto Python to teach their introduction to programming course. Apart from safety and security issues, the most cited reason for not preferring C as a first language is the fear of pointers and its arithmetic.

Why is it so?

Is it because previously CS departments were tied up with Electrical departments and the students took an architecture of digital logic/electronics course where they were aware of the hardware?

With the separation of CS and Electrical the study of the entire stack (from hardware to software) was abandoned and students have no idea what is happening at the machine level. They start programming at the high level (Python) and everything is very watered down. When they go on to learn languages like C they can't relate with the memory addresses and their arithmetic (pointers are basically syntax for memory addressing and management) because they don't know how the electronics operate.

This separation is becoming more and more prominent.

Also there is a aversion towards building something from scratch. The urge is to use a library that implements it. I mean, that is fine. But to really understand something it is best to implement it from scratch. First gen hackers and great programmers had to build everything from scratch even GUI frameworks were not available. We rarely see mastery of that sort nowadays. Everything is becoming too superficial.

And then there is functional programming. Racket's founders have a nice book How to Design Programs to teach beginners how to learn good coding. I mean it's great. It enforces good code, tests, no mutation to get rid of errors as much as possible. But the thing is to make functional programming languages efficient someone has to implement one level below the compilers/interpreters in such a way where pointer and efficient management of memory is unavoidable i.e. all the dirty work needed to make the beautiful land of functional programming. Don't we need to know how the languages work efficiently under the hood? Where do we get those engineers who create the happy land of functional programming one level above where users can do clean and neat programming? How do we debug under the hood with functional languages?

Memory is cheap. That doesn't mean we write sloppy non-efficient code and further overuse energy? Why are we so shy of space efficient programs? Just for the sake of correctness assurance?

Maybe, we are using abstraction the wrong way. It is the same case with math. Math education is getting dumbed down and the abstractions are increasing.




I have painful memories of my second-semester undergraduate "data structures and algorithms" class. Lots of difficult C++ programming projects; constant seg faults.

I didn't have any conceptual difficulties with pointers or pointer arithmetic. Rather, my difficulties were with the unforgivingness of the language: you had to be very anal-retentive and cautious, and I found it to be a slog. And when something went wrong -- which it inevitably and repeatedly did -- the error message would give you no context, no clue as to how to proceed. Just a bare "Segmentation fault".

There is value in this to be sure, but I didn't find it easy, nor did I enjoy it.

> Math education is getting dumbed down and the abstractions are increasing.

I am a math professor, and I find these statements contradictory. High-level math is largely about being able to understand and manipulate abstractions. Indeed, a lot of these abstractions are upstream of computation: understand the theory, and you can predict in advance how your computations will turn out.


I have a hard time understanding what exactly pointers is used for. Why should I use pointers? Because copying is often uneccessary?




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: