16 ms·
Massacring C Pointers (2018)
- kwillets 6y agoThat's not a bad interpretation. People forget that there were other programming models floating around at that time. In my youth I constructed a whole system of indirect referencing with register variables on an HP-41C calculator; when I got to C a few years later I found it doing many of the same things. If I had been more invested in the calculator programming I might have ended up like this author, but I quickly moved to the C programming model.
- ridiculous_fish 6y agoIn the same vein we have "The Annotated Annotated C Standard": https://www.davros.org/c/schildt.html https://www.davros.org/c/schildt.html A blast from the comp.lang.c past.
- moonchild 6y agoActually somewhat interesting is The New C Standard: An Economic and Cultural Commentary - http://www.knosof.co.uk/cbook/cbook.html http://www.knosof.co.uk/cbook/cbook.html
- bboreham 6y agoSchildt is one author who triggers deep revulsion in me. Some time around 1988 I bought one of his books on C, and found it was mostly generic padding about programming in general. Later I somehow managed to buy another book by Schildt and found it contained 80% the same text.
- _kst_ 6y agoAnd "C: The Complete Nonsense", a review of another Herbert Shildt book. https://www.seebs.net/c/c_tcn4e.html https://www.seebs.net/c/c_tcn4e.html
- shakna 6y ago> Another sticking point in this interpretation is Traister’s incomprehensible approach to writing functions that take a variable number of arguments. He does this by passing an arbitrary number of arguments to a function (the first being the number of arguments) and accessing them using offsets from the address of the first argument. This is one of those things that works by accident for some compilers for some platforms, but because it works for the developer, they think it's a brilliant idea. From what I remember, and I'm taxing my memory here, some of the early Turbo compilers did lay out arguments in this fashion, for DOS, when all optimisations were disabled. Most of the time. I do recall seeing similar layouts in some of the programs I played around with at the time, and thinking it was a genius idea. For context, I was about seven or eight years old.
- userbinator 6y agoBy "some" you mean "every stack-based right-to-left calling convention", which happens to be the norm for 16 and 32-bit x86. In contrast, varargs on 64-bit x86 is a mess: https://blog.nelhage.com/2010/10/amd64-and-va_arg/ https://blog.nelhage.com/2010/10/amd64-and-va_arg/
- saagarjha 6y agoA mess, but also fast.
- notacoward 6y agoThat convention is nowhere near as common as you present it to be. I was working on systems 30 years ago where the first few arguments were passed in registers. Many such systems. "Everything on the stack" was the rule for register-poor x86, which is why people weaned on DOS/Windows remain attached to it, but even back then it was far from a universal standard.
- dn3500 6y agoVarargs was not part of the language originally. If you look at the source code for printf() from Unix v7, I think you'll find it accesses its arguments by indexing off the address of the first one. I don't remember when varargs came along, but it was some time in the 1980s, and this book was written in 1990. Which is not to excuse the author. His description of how this works and why you would want to do it is just wrong.
- deleted 6y ago[deleted]
- klyrs 6y ago> If you browse search results for other books by Traister you’ll find a lot of questionable sounding titles ... [snip] ... Cave Exploring (1983) Yikes, that could kill somebody if he takes the same approach... otoh it looks like he was a scuba instructor? https://trackbill.com/bill/virginia-house-resolution-92-commending-robert-j-traister-sr/535889/ https://trackbill.com/bill/virginia-house-resolution-92-comm...
- gnfargbl 6y agoThe single Amazon review of Cave Exploring has a familiar echo: “Recommends that female cavers don't wear bras. So bad it is good. I bought it only because the National Speleological Society had it withdrawn from sale because it encouraged cavers to mark their route with a ball of string.” Bob actually sounds like a guy who had many talents. Writing books perhaps wasn’t one of them. https://www.findagrave.com/memorial/29007415/robert-joseph-traister https://www.findagrave.com/memorial/29007415/robert-joseph-t...
- eat_veggies 6y agoAs someone who's not very well versed in C, can someone please explain how I should interpret this function signature? char *combine(s, t) char *s, *t; {
- stephc_int13 6y agoThis is ugly old style C function signature. Obsolete since a long time ago (more than 20 years) Here is the "modern" equivalent: char combine(char s, char* t) {
- rwmj 6y agoUgly? I rather miss the traditional style of argument passing. My first real paid job used Microware's OS-9 compiler which only supported the traditional syntax, did absolutely no optimisation that I could discern, and made you use "register" if you wanted a local variable assigned to a register instead of always being spilled to the stack. (In fact looking back at it now I wonder if it was just a rebadged PCC). As an aside it's not always more verbose because you can group parameters by type, eg: int foo (c1, i1, c2, i2) char c1, c2; register int i1, i2; { ...
- saagarjha 6y agochar *combine(char *s, char *t)
- azdavis 6y agoThis is an old way of writing the type of parameters to a function. I believe the modern equivalent is char* combine(char* s, char* t) { ... } which means combine takes in two pointers-to-char and returns a pointer-to-char. Opinions differ on whether the * should be next to the type or next to the identifier. I prefer putting it next to the type.
- inspector-g 6y agoWhen I was learning C a couple decades ago, pointer syntax never made any sense to me until something suddenly clicked with “put it directly next to the type name and not next to the variable name”. Ever since then I have not been able to figure out why it is commonly taught next to the variable name. I mean, short of enabling declarations like: char *a, *b; But I have long since found the tradeoff to be worth the syntactic clarity.
- saagarjha 6y agoPrevious discussion from a couple years ago: https://news.ycombinator.com/item?id=17397823 https://news.ycombinator.com/item?id=17397823
- okareaman 6y agoIt's for sale on Amazon. 48% of reviewers have given it 5 stars: https://www.amazon.com/Mastering-Pointers-Tools-Programming-Power/dp/012697408X/ref=sr_1_8?dchild=1&qid=1599273504&refinements=p_27%3ARobert+J.+Traister&s=books&sr=1-8 https://www.amazon.com/Mastering-Pointers-Tools-Programming-...
- Too 6y ago48% of 7 reviews.... One of which only seems to praise the delivery time and condition of the book.
- deleted 6y ago[deleted]
- yesenadam 6y agoI looked at the vote breakdown, since 48% seems an impossible figure for 7 reviews. 29%, 43%, 57% – 2/7, 3/7, 4/7 – yes, but not 48%. It says "we don’t use a simple average. Instead, our system considers things like how recent a review is and if the reviewer bought the item on Amazon. It also analyzes reviews to verify trustworthiness."
- okareaman 6y agoShouldn't we all go bomb the book and give it one stars and write reviews telling everyone not to buy this book? After Kernighan calls it “malpractice”
- fortran77 6y agoI'd love to write a version of this book for Rust with the examples translated as close as possible within the constraints of the two languages.
- geophile 6y agoMy contribution to the genre of reviews of terrible books on C: https://www.amazon.com/gp/aw/reviews/B00NYBRH30/ref=cm_cr_unknown?ie=UTF8&filterByStar=one_star&pageNumber=1 https://www.amazon.com/gp/aw/reviews/B00NYBRH30/ref=cm_cr_un... (“This is a terrible book ...”)
- spacechild1 6y agoWow, the part about hash tables is quite shocking. I've just thrown my copy of the book (which I've never read) into the trash bin. Thanks for writing your review!
- fortran77 6y agoHmmm... > With BASIC, the key thing to know about most implementations at the time is that there were no functions and no scope aside from the global scope.[2] Take a look at DEF FN in the Applesoft Basic Manual: https://www.landsnail.com/a2ref.htm https://www.landsnail.com/a2ref.htm (To be fair, it wasn't used that much, but it was there.)
- syrrim 6y agoAuthor mentions in the footnote
- gpvos 6y agoI don't understand; you quote the reference to the footnote but haven't read it?
- fortran77 6y agoI think you do understand.
- gpvos 6y agoNo. Apparently you want me to spell it out; okay. Your comment is entirely unnecessary because what you write is already in the footnote. Why are you including the "[2]" in your quote, indicating that you have seen that there is a footnote, but haven't read it? Or have you read it and are posting it anyway? That's even harder to understand why you would do that. Also, making suggestive remarks is not very helpful.
- dullcrisp 6y agoFrom the detailed notes: > "A pointer to a function serves to hide the name and source code of that function. Muddying the waters is not normally a purposeful routine in C programming, but with the security placed on software these days, there is an element of misdirection that seems to be growing." (p. 109) It’s like a book by Calvin’s dad.
- 1vuio0pswjnm7 6y agoSo why is it that an editor would let these statements pass. If, say, the publisher was Addison-Wesley or Prentice Hall, would they make it into print. I am sure that this is not the only programming book that made it to publication with a lack of meaningful editorial oversight.
- xenadu02 6y agoThe worst part is the forward of the second edition says that the publisher hired a C programmer to review the book. That reviewer said "this book should not be published". They published it anyway!
- _kst_ 6y agoI just downloaded a free sample of the Kindle edition. Here's an excerpt from the preface: "Prior to publication of the first edition, the manuscript was reviewed by a professional C programmer hired by the publisher. This individual expressed a firm opinion that the book should not be published because “it offers nothing new -- nothing the C programmer cannot obtain from the documentation provided with C compilers by the software companies.”" The author's claim is that there was a pressing need for a book that just explains C pointers rather than covering the whole language. (It would be interesting to see the rest of what the reviewer wrote.)
- praptak 6y agoIt sounds like a scam ad that tries to make it sound like they are revealing a well guarded secret. "Professional C programmers hate him! A BASIC programmer discovers a clever way to use pointers..."
- kabdib 6y agoFor a while I had a gig writing HR software, and I read a bunch of books on conducting technical interviews. One particular gem of a book -- the title escapes me -- had example interview questions for some popular programming languages. I don't know about the COBOL, XML and SQL chapters, but the C and Java chapters were terrible: Q: "How do you get the size of a file?" A: "Call open, and then sizeof." ... is the only one I recall, but they all ranged from "awful" to "not even wrong". Over my years of job hunting I'm slightly disappointed that I've never been given a question from it. :-) This is all fun and games until you run into this kind of code in production. I once had to do an emergency rewrite of some firmware by someone who did not appreciate the benefit of functions. That one was so bad that I stopped looking at the original code for any reason because I was afraid I'd accidentally adopt one of the author's many, many misinterpretations of the hardware, or of base reality.
- smabie 6y agoWas the book intended for people who didn't know how to program but were for some reason interviewing a programmer?
- laumars 6y agoIt’s not that unusual of a situation. You might have other technical teams but your lead developer(s) leave. These days you can outsource technical tests to online businesses that specialise in that kind of stuff but that wasn’t always an option, particularly if you travel far back enough in time, and hiring contractors to support you during the recruitment process is often seen as too expensive for some businesses.
- m-ee 6y agoI once has to rewrite legacy firmware where the original author didn’t believe in .c files. You can still compile with only header files (but only if it’s all headers, no mixing what he did with normal structure), but I still wonder why he thought that was a good idea. He works for Facebook now.
- deleted 6y ago
- smabie 6y agoThis stuff is just amazing. Was this guy, like an adult when he wrote this book? I knew more C when I was 12.
- smabie 6y ago"At the bottom of the heap in a pointer stack is the ultimate object."
- jnurmine 6y agoHah, when I read this, I envisioned a movie poster of a B-class "cyber" action movie and this line under a picture of people holding keyboards and pistols.
- Droobfest 6y ago> His terminology is all over the map and typically inaccurate, if not plainly wrong. > Expressions “return a value.” > “A pointer is a special variable that returns the address of a memory location.” I don't see how these are clearly wrong? I guess the 'returning' is problematic? Somehow I feel this was written with an air of superiority, the author doesn't expand on anything. I get that feeling a lot with articles about c.
- masklinn 6y agoThe first one is a bit odd, and in C expressions specifically don’t always return values: void functions. The second one reads really strange to me, and variables don’t return things.
- TomSwirly 6y agoI've been writing C since the 1980s. Sorry, this book is not just bad but astonishingly bad. Your examples are just wrong. "Returning" has a very specific meaning in programming. An expression does not "return a value". A pointer very very much does not "return the address of a memory location". The code example given was utterly awful. If you cannot see why that code example is almost guaranteed to cause problems, you might not want to continue in this discussion...
- threepio 6y agoIs Robert Traister an actual human being? Or just a pen name that the publisher puts on quickie books? Or a name, like Alan Smithee, applied to books that have gone wrong?
- susam 6y agoFortunately, 18 years ago, I began learning C from the book The C Programming Language, 2nd ed. written by Brian Kernighan and Dennis Ritchie. The subject of pointers was generally believed to be scary among fellow students and many of them bought pretty fat books that were dedicated solely to the topic of pointers. However, when I reached Chapter 5 of the The C Programming Language (K&R), I found that it did a wonderful job at teaching pointers in merely 31 pages. The chapter opens with this sentence: > A pointer is a variable that contains the address of a variable. The exact point at which the whole topic of pointers became crystal clear was when I encountered this sentence in § 5.3 Pointers and Arrays: > Rather more surprising, at first sight, is the fact that a reference to a[i] can also be written as * (a+i). Indeed, it was easy to confirm that by compiling and running the following program: #include <stdio.h> int main() { int a[] = {2, 3, 5, 7, 11}; printf("%d\n", *(a + 2)); printf("%d\n", a[2]); printf("%d\n", 2[a]); return 0; } The output is: 5 5 5 C was the first serious programming language I was learning back then and at that time, I don't think I could have come across a better book than K&R to learn this subject. Like many others, I too feel that this book is a model for technical writing. I wish more technical books were written like this with clear presentation and concise treatment.
- vanviegen 6y agoIt is a good book. But to be fair, not many modern languages are as simple (low number of concepts) as C.
- Yajirobe 6y ago> A pointer is a variable that contains the address of a variable. Doesn't it technically also contain its own address? So it contains the address of another variable and the address of itself. Pointers are hard...
- nnq 6y ago> Doesn't it technically also contain its own address Huh? Then you probably don't understand the meaning of "contains" here. Or what variables are in general. Variables are hard...
- beervirus 6y agoApparently he also wrote a book about hand loading ammunition,[0] and I wonder if that’s full of dangerous advice too. [0] https://www.thriftbooks.com/w/complete-reloading-guide_john-e-traister_robert-j-traister/492668/#isbn=0883171945 https://www.thriftbooks.com/w/complete-reloading-guide_john-...
- mabbo 6y ago> In the preface of the second edition it says that the first edition was reviewed “by a professional C programmer hired by the publisher.” That programmer said it should not be published. That programmer was right, but the publisher went ahead and published it anyway. Reminds me of https://m.xkcd.com/1096/ https://m.xkcd.com/1096/
- moonbug 6y agothis book is a travistery
- Xophmeister 6y agoIs the author still alive? These books were published in the early 90s, which wasn’t _that_ long ago. I’m not advocating a lynch mob on an old man, of course, but his story/rebuttal/repentance might be interesting.
- hzhou321 6y agoIn stead of worshiping "The C Programming Language", why don't we appreciate how Kernighan only uses the bad code example but didn't single out the book and author? Honestly, I feel like I am witnessing a class room teasing act with all the comments just resonating. Do we really feel such an urge that if we don't tease this old author (not just the book or code) loud, it will lead a new generations of young programmers astray?
- danmg 6y agoThese books are available on libgen if you want to see them for yourself: https://b-ok.xyz/book/2368114/60fa20 https://b-ok.xyz/book/2368114/60fa20 https://b-ok.xyz/book/2368115/f2ecc8 https://b-ok.xyz/book/2368115/f2ecc8
- IndexPointer 6y agoDamn. Those code examples are complete insanity. Half won't even compile. It's like if I tried to write a textbook on how to do neurosurgery.
- saagarjha 6y agoI mean, how hard can it be? You just cut open their head, mess around it a bit…
- cassepipe 6y agoC beginner here. C abstractions don't make sense if you don't grok what the stack and the heap are and how they work.
- chihuahua 6y agoI wonder if the author should feel honored or dejected that Woz took the time to read the book and write a detailed article explaining why it's a terrible book. That's the question of how the author should feel. I'm sure that if he found out about Woz' review, he would dismiss it by saying "who is this Wozniak guy anyways, he probably knows nothing"
- sgerenser 6y agoIt’s not that Wozniak.
- deleted 6y ago[deleted]