Hacker News new | past | comments | ask | show | jobs | submit login

This book introduced me to modern languages, from my previous experience coding in assembler. It inspired the millions of lines of code I've written since.

I now understand why my subsequent programs, and those of many in my generation, have been riddled with bugs for 3 decades.




K&R is hardly the only book written about C, nor is it the best. You should definitely not stop learning about a language after you've read just one book about it.

K&R C was best practice in 1980 or so, since then we've learned a lot about C, about what to do and what not to do. If you still program C like it is 1980 then you can't really blame that on a book from 1978.


I am midway through K&R, but now I am curious, what other book would you suggest?


Popular suggestions (not introductory):

    C Interfaces and Implementations (David R. Hanson)
    Expert C Programming (Peter van der Linden)
I'm also a fan of C Programming: A Modern Approach (K. N. King) as an introductory book, but it's very different in intended audience from K&R. King is writing for students, and he assumes nearly nothing. K&R are really writing for experienced fellow programmers, I think. So it's an apples to oranges comparison. But King is certainly more modern. He includes a fair amount of C99 material. The writing can't compare with K&R. It's nowhere near as dense or elegant. But if you find parts of K&R a bit too dense and elegant, it's a good trade-off. (I used them both in tandem while trying to learn C this summer. It worked well for me. When King got too verbose, switch to K&R. When K&R lost me, switch to King.)


King's book was my introduction to serious programming when I was younger. In an era of my life where I usually prefer ebooks, I still have King's book, in dead-tree format, and love it.


IMO, this is a better book at explaining C clearly: "advanced programming in the unix environment" by W. Richard Stevens. Don't be fooled by the title.. it's a beginner book.


> Don't be fooled by the title.. it's a beginner book.

I never know what to do with comments like this. It's obviously not a beginner's book. At the very least, it assumes that you know C. If your response is "C is a small language. You can learn it by reading <some-other-thing>.", you're admitting that APUE is not a beginner's book. If your response is, "C is a small language. You can learn it by reading APUE itself.", then I call bullshit. Is it theoretically possible, sure. But is it a natural way for a true beginner to learn C? Certainly not.


> It's obviously not a beginner's book.

What do you mean by this? You obviously have NOT read it. I have. I'm telling you it is a beginner book. It does not assume you know C or anything else. It has nothing to do with the size of C. Grabbed it off my bookshelf -- he starts off telling you how to login to a unix system. How advanced can it be?

This is literally the book that taught me the basics of C within a week -- the first language I learned (15 years ago). So it is definitely a beginner book IMO.

Edit: I will say, he does get into some more advanced things toward the end. Which is why I like the book.. he starts off very basic, and by the end, he's covered the basics of interprocess communication, shared memory, etc.


I have read the book. It does not teach you C. It assumes that you know the language. It does not teach you anything about the syntax of the language.

He does not tell you how to log into a UNIX system. He tells you what happens when you log into a UNIX system. (That is a big difference. Compare the first chapter of Kerrigan and Pike's The Unix Programming Environment, which actually does teach about terminals and explicitly talks about how to log in and what a login is -- for a complete beginner.)

Here's the first bit of code, from page 5:

    #include "apue.h"
    #include <dirent.h>
    
    int
    main(int argc, char *argv[])
    {
    	DIR		*dp;
    	struct dirent	*dirp;
    
    	if (argc != 2)
    		err_quit("usage: ls directory_name");
    
    	if ((dp = opendir(argv[1])) == NULL)
    		err_sys("can't open %s", argv[1]);
    	while ((dirp = readdir(dp)) != NULL)
    		printf("%s\n", dirp->d_name);
    
    	closedir(dp);
    	exit(0);
    }
My point is very simple: If you do not know C and especially if you also do not know any programming language, it would require either magic or another book or tutorial to figure out the syntax or semantics of those lines. Why is the first include thingy in quotes and the second in brackets? What is an include thingy anyhow? What is DIR? Why do some things have a * in front of them? When are semicolons used? Not every line ends in one, but most do - why? What is the -> used for? When do I use parentheses and when do I use braces? What is argc or argv? Are those names important? What is NULL? Why are some things all capitals and some not. Does that matter? He doesn't answer any of these questions (nor should he), because the book is not meant to teach you C. It assumes that you already know C.

It is not a beginner's book.


Here's a bit of code from page 10:

  #include "ourhdr.h"

  int
  main(void)
  {
    printf("hello world from process ID %d\n", getpid());
    exit(0);
  }
Ch 7 is the environment of a unix process. 7.2: "argc is the number of command line arguments and argv is an array of pointers to the arguments. We describe these in Section 7.4." exit codes are discussed in section 7.3, where he also talks about 0 in exit.

Granted, he does not discuss the syntax or NULL...

Looking through it.. I'll agree it isn't a beginner book. Intermediate at worst though.


Hmm... Having not seen the first edition of the book (which is the edition you must have given that you used it 15 years ago and it was updated 8 years ago), it's possible that your assessment of its elementary content is specific to that edition.

However, the second edition of the text is by no means elementary; unless you are conflating beginner literature with comprehensive literature, and the text is certainly comprehensive.

I'll grant you that Chapter 1 is a summary and introduction to the entire book with little challenging or novel material for someone experienced with UNIX and C, but many advanced texts have introductory sections. A large portion of the "The Art of Computer Programming: Fundamental Algorithms" is essentially a review of the elementary mathematics necessary for the analysis of algorithms, but I would never call TAOP a "beginners book"!


This thread has been interesting for me. The first time I've opened the book in 13-14 years probably. Not exactly what I remembered. So just ignore my posts :)


Harbison & Steele, "C: A Reference Manual".


You could do a lot worse than getting a copy of Sedgewick 'algorithms in C'.


Don't blame K&R because it took you 30 years to notice that one of the many widely available string libraries might be a good idea.


It was a poorly worded joke. US, irony etc.

That book was a first step for many of the devs that build many of the technologies that support everything we do online today.




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

Search: