Live data from Hacker News

Massacring C Pointers

wozniak.ca

51–60 of 300 posts

Re: Massacring C Pointers

#51
When I was learning C in the eighties, I bought a book about 3D programming, the worst programming book I've read. I believe that examples worked, at least the ones that I typed did, but the style was atrocious. The concept of function parameters seemed to be totally alien to the author. The idiot created x1, X1, x2, X3, x, xthis, xthat... variables instead. He was a former BASIC book author too.

I can't warn you because I put it to the trash bin long ago.

Re: Massacring C Pointers

#52
Heh, not only this but there are also plenty of C++ books that are literally less than worthless.

Additionally another common domain of clueless writing is computer graphics and the related math. There are so many articles written by enthusiastic people (no doubt) where the information is just adding noise. Finding trustworthy good quality information requires that you know a considerable amount already so you know what is good and what is not (talking about online content here) :)

Re: Massacring C Pointers

#53
post #17

Earlier quoted context omitted.

I haven't touched C in years, but here's my descending "wtf" list: 1. Returns pointer to stack-allocated data, which immediately becomes invalid. Instead, it should be using some sort of allocation (e.g. 'malloc'), or taking in a destination pointer. 2. 'r' is arbitrarily set with length 100. Smaller strings don't need all that space, and larger strings definitely will overrun. 3. The function signature is really awk…

> 'strcpy' should usually be replaced by 'strncpy' Sorry to butt in, but this is a bit of a trigger for me: I’ve had to fix a number of programs infected with this idea. The main problems with strncpy are: When the source string is shorter than n, strncpy will pad the target to n bytes, filling with zeros. This is bad for performance. When the source string is longer than n, strncpy will copy n bytes but _not_ nul-te…

The least bad options seem to be strl* or snprintf(..., “%s”, ...) but yeah nothing is perfect.

Re: Massacring C Pointers

#54
post #26

It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration. - Dijkstra, "How do we tell truths that might hurt?" (1975) The author, Traister, has came from BASIC. We have the explanation.

Well that is a dumb and inaccurate statement if ever I've read one. I mean I'm sure there might have been some nugget of truth back in the 70s in that it might have been frustrating to teach C or FORTRAN to BASIC programmers but it has as much relevance these days as any of the other memes people like to quite from yesteryear. I certainly managed the transition from BASIC to Pascal with ease and definitely follow goo…

I think there’s some truth lurking in there somewhere. I was an Oracle DBA for years, and recently started working on a NoSQL serverless project. I think I’ve been doing a pretty good job of it, but it took a huge amount of effort to get my mind around the new principles. The reason being just about everything I’d learned about RDBMS was a total footgun when it came to NoSQL design. My low level knowledge of how RDBMS operate helped me get there in the end, but the initial designs I came up with were packed full of despair and sadness.

Re: Massacring C Pointers

#56

It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration. - Dijkstra, "How do we tell truths that might hurt?" (1975) The author, Traister, has came from BASIC. We have the explanation.

Heh, I've started with machine code, it's not unlike BASIC. Command addresses instead of line numbers, gotos aplenty, global variables.

Re: Massacring C Pointers

#57

Heh, not only this but there are also plenty of C++ books that are literally less than worthless. Additionally another common domain of clueless writing is computer graphics and the related math. There are so many articles written by enthusiastic people (no doubt) where the information is just adding noise. Finding trustworthy good quality information requires that you know a considerable amount already so you know w…

Didn't some of the C++ books have to be crappy in some ways due to limitations of free (as in beer) compilers with arbitrary limitations? One I vaguely remember was a ridiculously (even for the time) limited stack size, so a lot of examples had to do unnecessary allocation just so readers could compile.

I think it was this book (https://www.amazon.com/Flights-Fantasy-Programming-Video-Gam...) that taught me 3D programming better than anything else. The code was readable, the maths was well explained and it included sections on how to do things without those newfangled maths co-processors. I'd love to buy a copy now just to see if it really was a good book or if it led me astray.

Re: Massacring C Pointers

#60
post #51

When I was learning C in the eighties, I bought a book about 3D programming, the worst programming book I've read. I believe that examples worked, at least the ones that I typed did, but the style was atrocious. The concept of function parameters seemed to be totally alien to the author. The idiot created x1, X1, x2, X3, x, xthis, xthat... variables instead. He was a former BASIC book author too. I can't warn you bec…

He was a former BASIC book author too

Hmm, I'm starting to see a pattern. Is it possible BASIC, plus lack of internet back in the day, plus attrocious books are the reasons for truning poeple into terrible programmers? I happen to know only a couple of seniors but without exception their code, no matter what language written in today, is horrible on all fronts. I used to think it was a lack of attention to detail, their lack of wanting to strive for even the tiniest bit of more than just 'good enough for tady'. Possibly stemming from lack of education and lack of continuous self-education. But maybe there's more to it. Maybe they were influenced by a bad book. And/or by a not-so-optimal language like BASIC.

Post reply on HN