lainchan / λ

K&R commentary thread

Church · 2017-04-30 19:52
I think we can all agree that K&R is the most hyped programming book of all time. Ive read the first 100 pages and I cant see what is so great about it, it just seems like any other programming book. But too many people I respect say that it is the best book for learning programming so I would like to go through the code in the book together with all you guys to try and see if I can discover what all these deep concepts everyone is talking about are. So lets skip the hello world and go directly to the Fahrenheit-Celsius converter. The first version of this program is on page 12 and the last one which uses a for loop is on page 17. I will paste the first and last versions of this program and lets see what we can find: pg12 #include <stdio.h> /* print Fahrenheit-Celsius table for fahr = 0, 20, ..., 300 */ main() { int fahr, celsius; int lower, upper, step; lower = 0; /* lower limit of temperature scale */ upper = 300; /* upper limit */ step = 20; /* step size */ fahr = lower; while (fahr <= upper) { celsius = 5 * (fahr-32) / 9; printf("%d\t%d\n", fahr, celsius); fahr = fahr + step; } } pg17 #include <stdio.h> #define LOWER 0 /* lower limit of table */ #define UPPER 300 /* upper limit */ #define STEP 20 /* step size */ /* print Fahrenheit-Celsius table */ main() { int fahr; for (fahr = LOWER; fahr <= UPPER; fahr = fahr + STEP) printf("%3d %6.1f\n", fahr, (5.0/9.0)*(fahr-32)); } This just looks like a simple program to me, nothing special about it. Shall we go on to the file copying program on page 18 or am I missing anything?
Random · 2017-04-30 21:18
K&R is the definitive introductory book for C. It is important because it has influenced the coding style of many C programmers. It's a very solid book that explains well the core concepts and idioms you need to know if you want to program in C on a Unix system. Yes, it's a very basic, simple book. That's on purpose. I've never seen anyone call it "deep".