5 ms·
What is your opinion on K&R?
by mozball 4y ago
What is your opinion on K&R?
- fn-mote 4y agoIt's great for what it is, but the language and style have come a long way since then. It would be better to learn "Modern C" (this is the title of a book but also at least learn C99 not K&R C). E.g., people like the book by Jens Gustedt. I'm ambivalent about it, but it sure machine-guns the important points. [1] https://hal.inria.fr/hal-02383654/file/ModernC.pdf https://hal.inria.fr/hal-02383654/file/ModernC.pdf
- Koshkin 4y ago> not K&R C K&R the 2nd edition of book teaches ANSI C. (It is still the best intro into the basics of C.)
- flohofwoe 4y agoIt's much too awkward IMHO, C99 and onward almost feels like a whole new language (mainly because of struct literal and designated init support).
- rightbyte 4y agoNot being forced to declare symbols in the beginning of the scope is the real game changer I say. K&R or C89 without e.g. GNU extensions is really annoying to use.
- bluecalm 4y agoIdk about that. I think it's code with everything declared at the beginning of the scope is easier to read and understand. Every time I see code written in this style (Git, Linux) it's easier to build a mental model of what is happening.
- stusmall 4y agoNot the person you are replying to, but here are my thoughts. It sounds like OP is looking to learn C for historical and contextual reasons, and for that K&R is perfect. The history of C is very K&R-centric. For modern, practical C programing it is missing a lot though. It is a short, simple, from the original authors introduction to the language itself. There is nothing about how to test your code, how to set it up for long term maintainability, how to mitigate some of the security downfalls or even any of the features added since C89. It's a good technical book. A great one for it's time and subject matter. But that caveat is important, it needs to be taken in context of the time. It shouldn't be the first, and absolutely not the only, book you read if you are writing modern production C in 2023.
- asveikau 4y ago> or how to mitigate some of the security downfalls. I think I'd go further, there are places where it advocates downright unsafe practices. Eg. It's been a long time, but I thought I remember it introducing gets() unironically, without any caveat. For those that do not know, there is no safe use of that interface possible.
- sfpotter 4y agoIf you're just beginning with C, it doesn't matter. If anything, it's better to be exposed to these unsafe practices and make mistakes with them in the very safe environment of your own home, where absolutely no one cares what you're doing. K&R C is an excellent learning resource primarily because it's extremely strong pedagogically. Read K&R and then move onto something else later when you're done with it. If you eventually get a job doing something with C, then you'll learn on the job what's important to the job you're doing.
- convolvatron 4y agoI kinda disagree. global hidden state under APIs is a really awful idea to put in someone's head. I think it also presents the notion to neophytes that there is magic under there
- suprjami 4y agoIt's wonderfully written. I'm a big fan of both Dennis Ritchie and Brian Kernighan personally. However the book was last updated in 1988 and I prefer C99+ for almost every feature it adds. If I'm going to recommend just one book it will be something newer.
- sn9 4y agoIt's one of the best examples of technical writing in the field. A good introduction to the basics of the language. Read it for culture. Read something else for safe C writing in a modern environment. Books like Modern C and Effective C are good starts.