3 ms·
There is nothing about pointers that makes them unusually hard to keep track of. If you are prone to goofing on pointer arithmetic, then you're almost certainly
by mtdewcmu 13y ago
There is nothing about pointers that makes them unusually hard to keep track of. If you are prone to goofing on pointer arithmetic, then you're almost certainly going to run into problems even if you never use pointers, because arithmetic is hard to avoid in programming.
I don't use C for everything. When I do write C, I try to keep memory as simple as possible. I avoid allocating dynamic memory wherever possible, and when I do use malloc, I try to keep the logic around the pointers as simple as possible. This is beneficial all around, because malloc and free are not especially fast, and if you use them for everything, you won't see all that much benefit over a high-level language.
It's like building your own house or making your own clothes. There's no guarantee that you'll do a better job and get a better result than if you went the easy way.
- pjmlp 13y agoFirst of all, in other similar languages like Modula-2 and Ada, there is no need to use pointer arithetic as much as C developers do. Even in C, most developers that use it, are doing micro-optimizations without ever testing their assumptions in terms of performance. Finally, as a single developer it is easy to keep track of most C traps, the problem is when a project has more than a few developers, with different skill levels. Then the party starts.
- mtdewcmu 13y agoThere are probably lots of people writing bad code in C, I'll grant you that point. But that isn't a property that's built into the C language itself. I think you are attacking a straw man. My original point was just that it's possible to write very fast programs in C.
- pjmlp 13y ago> But that isn't a property that's built into the C language itself. It is, as it makes very easy to blow your leg off. C only works properly in the hands of small teams with AAA developers.
- mtdewcmu 13y ago>It is, as it makes very easy to blow your leg off. I have never seen a bug-proof programming language. If a language lets you do anything at all, then it will let you write bugs. So I don't see it as a weakness that C allows you to write bugs. If you have easy access to memory, then you can easily corrupt memory.