Live data from Hacker News

Massacring C Pointers

wozniak.ca

71–80 of 300 posts

Re: Massacring C Pointers

#71
post #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, th…

You're not the first to notice a pattern, and you're in good company:

> 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.

  --Edsger W. Dijkstra 
Though, to be fair, he would likely say that about a lot of mainstream languages today. Iirc he was very fond of Miranda, which in many ways was a precursor to Haskell.

Re: Massacring C Pointers

#72
post #3

I always wondered about the C tutorials Brian Kernigan mentions in his talk ( https://www.youtube.com/watch?v=8SUkrR7ZfTA ) , many of the examples seem intentionally designed to be incorrect by some trickster spirit. Now I know the even darker truth.

The exact same code sample appears in the talk as in the article.

Re: Massacring C Pointers

#73

A few years ago, I saw a classroom video (I would guess ~8-10 year olds, in the American public school system) as a demonstration of a teacher's technique called "my favourite wrong answer". She would have them solve a problem (a math problem, in this particular case), collect the answers, show the distribution of the answers, and then pick out one answer (possibly with the student's name redacted) as her "favourite…

The issue with really learning computer science outside top well known schools is that you're basically on your own for education (or worse if taught wrong). Open source software somewhat teaches you things but usually by trial by fire.

Really? I went to a non-top school and putting aside the formal education component, I felt like I also had plenty of co-learning. That is, I remember many study groups where we helped each other learn, including for programming.

I certainly didn't feel like I was on my own.

Re: Massacring C Pointers

#74
post #60

Earlier quoted context omitted.

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, th…

You're not the first to notice a pattern, and you're in good company: > 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. --Edsger W. Dijkstra Though, to be fair, he would likely say that about a lot of mainstream languages today. Iirc he was very fond of Miranda, which in many w…

To be fair, he said that about a lot of mainstream languages back then. That quote is from EWD498 at http://www.cs.utexas.edu/users/EWD/transcriptions/EWD04xx/EW... . The larger context is (the rest of the comment quotes him):

FORTRAN —"the infantile disorder"—, by now nearly 20 years old, is hopelessly inadequate for whatever computer application you have in mind today: it is now too clumsy, too risky, and too expensive to use.

PL/I —"the fatal disease"— belongs more to the problem set than to the solution set.

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.

The use of COBOL cripples the mind; its teaching should, therefore, be regarded as a criminal offence.

APL is a mistake, carried through to perfection. It is the language of the future for the programming techniques of the past: it creates a new generation of coding bums.

Re: Massacring C Pointers

#75
"...But like analyzing a terrible movie that somehow gets made, it's more fun to reason through the “behind the scenes” parts..."

I do too. Many times I find it much more interesting understanding how the sausage is made than what the actual sausage tastes like.

This is a great meta review. As somebody who's just published a book for tech teams, I need to be acutely aware of my own work to make sure I'm not falling down the same hole: taking a little bit of knowledge and and trying to fluff it out to appear to be a comprehensive body of work.

It's not just the 80s and old coding books. There has been quite a trend over the last decade or so of people over-publishing (I guess that's the term). Promising all sorts of things while delivering on little.

In some ways I think this is okay. The received wisdom is that you don't have to know everything, you just have to know more than the reader and be able to explain how to move them a bit forward. Perhaps the key is attitude. Woz says "..'Ive always found the authors come from a position of earnestness, attempting to draw the best conclusions based on decent principles and what they knew at the time they wrote it..."

A little humility, careful scoping, and honesty in a tech book can go a long ways. (Insert long discussion here about whether people would buy such a book, and how people are much more naturally attracted to books with a strong emotional impact "Make money with C Now!" than they are books that simply try to helpfully explain something without all the glitz) There is a natural tension at work here.

Re: Massacring C Pointers

#77
post #60

Earlier quoted context omitted.

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, th…

I would say "it depends". Just as poor programmers came later from Visual Basic, or MSVC++ (somehow we went through a phase were everyone coming for interview with MSVC++ actually had C with classes, and for a while it was a warning sign and standing joke at the place I then worked). Getting people who claimed C++ who actually knew it was pretty challenging around the millennium. In the 80s just about everyone who ha…

Might be totally wrong, but it's possible that MSVC++ programmers typically knowing 'C with classes' might come from the gaming world, as that's a fairly accurate description of some very popular game engines (Valve's Source engine[1] being the one I'm most familiar with, where e.g. std::string is unused in favor of char/wchar arrays).

[1] https://github.com/ValveSoftware/source-sdk-2013 (originally released in 2004)

Re: Massacring C Pointers

#78
post #26

Earlier quoted context omitted.

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 RDBM…

The fact you got there in the end disproves your point. You'd expect any first attempt at a new language, let alone paradigm, to be less than perfect. You can't expect people to be experts before they've even studied a subject. But to argue that any one particular language damages beyond repair ones ability to learn another is simply elitest hyperbole.

Re: Massacring C Pointers

#79
post #27

Yesterday I encountered a similar program on a HN comment chain as shown in this link. I am genuinely confused as to why this program is bad. I am a student and I do not know the best practices regarding pointers, but it is how I would write a program to combine two strings. Can someone please elaborate why it is bad? Are their any good resources to fill gaps in my knowledge? Thanks in advance. Edit: Thank you guys f…

Most of these points are covered by the other comments. As a C programmer professionally, I'll go into a little more depth, and offer an alternative implementation for comparison. The function in question: char *combine(s, t) char *s, *t; { int x, y; char r[100]; strcpy(r, s); y = strlen(r); for (x = y; *t != '\0'; ++x) r[x] = *t++; r[x] = '\0'; return(r); } 1. The array 'r' is allocated on the stack, and returned fr…

    if (NULL == s)
Ouch.

I haven't seen a single case where this abomination actually helped catching the fearsome 'if (s = NULL)' typo. One needs to be a sloppy typist, not paying attention to what they write, not proof-reading the code before committing and ignoring compiler warnings for this disaster of a notation to be even remotely justified.

Post reply on HN