Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Is K&R still a relevant read for a beginner? Is there a 'K&R' for C++?
5 points by boppo1 on Dec 18, 2021 | hide | past | favorite | 8 comments


No, K&R is not a relevant read if your goal is to learn to read and write idiomatic C++. And, I don't know what is. Honestly, I'm super happy that through a job change I get to write C again and not C++.

C++ is just so big. C++ has changed so much from 03 through 11, 14, 17, and now/soon 20 and 23. So much can come from external class libraries such as Boost. And the exact features you can use depend on your compiler, its vintage, and any legacy code you've got in your application.

Now, references, cppreference.com is excellent as a website.

I do see that Stroustroup himself has a 2018 book titled "A Tour of C++". I can't vouch for it, but it may be worth checking into.


I can vouch for it. To my way of thinking, "A Tour of C++" is the closest thing to K&R for C++. It's not a complete all-you-need-to-become-a-professional-C++-programmer book, but K&R wasn't either. It gives a good look at what's going on under the hood and why. And it's amazing how complete it is for how thin it is.


When Stroustroup created C++ it was a superset of C. In fact, the earliest compilers for C++ were a pre-processing pass that generated C code to be compiled by (then) K&R and soon ANSI C compilers. Since then C++ has grown massively and has specialized compilers that optimize the many new constructs. Many C++ programmers only use a subset of the current language. A common team situation is that every team member uses a different subset of C++.

IMO since C is the ancestor of C++ as well as ObjectiveC/Swift, C#, JavaScript, Java by learning pure C, you gain the foundations from which to learn not just C++ but those other languages.


There are minor exceptions that make C++ not a superset of C. See https://stroustrup.com/bs_faq.html#C-is-subset and a full list at https://stroustrup.com/3rd_compat.pdf .

Other languages can be transpiled to C (f2c from 1990 for Fortran, p2c from 1989 for Pascal) so cfront's C++->C conversion isn't really connected to the idea of superset-ness.

I've heard the argument that learning Latin first makes it easier to learn the Romance languages which derive from it. I don't believe it, in part because I found what helps me most to learn a language is actually having a need to use it (like visiting Germany for the first time after a year of German classes at school.) Start by learning the language you're going to use. Don't start with Algol simply because it's the historic foundation to C, Pascal, PL/1, etc.

Someone starting with K&R as a way to learn C++ will need to discard some styles, like using malloc/free. (And someone starting with Latin as a way to learn Spanish means discarding most of Latin's case system.)



It's outdated in many ways. You might try instead "Modern C" by Jen Gustedt, which is free online [0]. (This recommendation assumes previous programming experience.)

[0] https://gustedt.gitlabpages.inria.fr/modern-c/


I'd like to chime in my two cents that are likely controversial. I preferred a different C book to K&R: "K. N. King. C Programming: A Modern Approach". Second, I could not grok Stroustrup's writing style. I preferred Stanley Lippman's C++ Primer. A new version of that has been around the corner for years .. current ETA is mid next year,


I think the new edition is vaporware. The publisher's website now says 2023: https://www.informit.com/store/c-plus-plus-primer-9780135161....




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

Search: