Slashdot Mirror


C

Craig Maloney submitted this review of Addison-Wesley's entry in the tough field of books on C (book title: C), and pulls no punches in comparing it to others. He says it's slightly above average, but that "experienced programmers will likely pass on this book." Read the complete review below for his reasoning. C (Addison-Wesley Nitty Gritty Programming Series) author Klaus Schr�der pages 400 publisher Addison-Wesley rating 5.5 reviewer Craig Maloney ISBN 0-201-75878-4 summary A slightly better than average C book with some very good points, but poor delivery.

Lost in the Company of Giants

It's hard not to take a book like C and compare it to such acclaimed and trusted books as K&R, Expert C Programming, and other lesser known, but equally good tomes. Unfortunately C doesn't really compare with many of the other classic books covering the C language. For starters, the writing in this book isn't quite up to the same caliber as the other books. Part of the problem with this book is language. English does not appear to be the author's native language. There are sentences in this book that require a few glances to glean the full meaning. C is difficult enough to present without a language barrier introducing more problems. Another problem is organization. The ideas presented at the beginning of the book are muddled and disjointed, with multiple ideas introduced but not formally explained until later. Beginners will have a terrible time working through this book without becoming quickly confused, and experienced programmers will likely pass on this book in favor of the other well-known books.

Not All Bad

The book is not all bad, however. The examples in the book are plentiful and are based on tried-and-true examples found in books like K&R. There are some idioms that are used in the examples that will irk the more structured programmers (not using braces in certain areas being the biggest example), but most of the examples are pretty good. Also, the explanations of the more advanced topics are relatively good considering how confusing the more basic material is. Memory management is explained well, with clear diagrams (although the programs are a bit confusing without a careful eye).

So What's in it for Me?

Addison-Wesley is clearly marketing this book to the same crowd that purchases quick-learning books. Unfortunately beginners purchasing this book will quickly find themselves lost amid the confusing descriptions in this book. Those who manage to muddle through will find some tasty bits of information locked inside, but the work involved in getting there outweighs the rewards. Most programmers will probably want to leaf through a copy of this book before purchasing it to make sure they'll get the most out of it.

You can purchase C from Fatbrain. Want to see your own review here? Just read the book review guidelines, then use Slashdot's handy submission form.

23 of 299 comments (clear)

  1. Only two C books needed: by Ars-Fartsica · · Score: 3, Interesting

    K&R and "Advanced C Programming By Example" by John Perry.

    1. Re:Only two C books needed: by theCURE · · Score: 4, Funny

      Yeah because if you don't buy "Advanced C Programming By Example", then K&R might fall over on the shelf.

      --
      "i can never say no to anyone but you"
  2. Re:don't waste your time by geoswan · · Score: 4, Informative

    If you are reading this discussion because you are planning to learn C, know that not only is K&R's book a very fine book, but there is geek cachet in being able to say "I learned C from Kernighan and Ritchie".

  3. Rule of Thumb by pizen · · Score: 5, Interesting

    One of my CS profs (Georgia Tech people probably know who I'm referring to) gave the class advice on buying a C book: Flip through the book. If malloc isn't covered, put it back. If malloc is covered in an appendix, put it back. If the book contains the line cp=realloc(cp,n); then "burn it! Burn it right there in the store! Burn all of them!"

    1. Re:Rule of Thumb by megas · · Score: 4, Funny

      The professor is Professor Jim Greenlee, he has fabulous quotes such as
      you must code until your fingers are bloody stumps and you wake up with a keyboard imprint on the side of your face
      and they're collected at http://swiki.cc.gatech.edu:8080/cs2130/57

    2. Re:Rule of Thumb by pizen · · Score: 3, Informative

      The problem is not with realloc. The problem is if realloc fails it returns null and you lose the pointer to memory that is cpand thus creates a memory leak. The better code would be:

      if((temp=realloc(cp,n))!=null)
      cp=temp;

  4. Above average? by Dephex+Twin · · Score: 4, Funny
    He says it's slightly above average

    Actually, "C" is about dead-on average, I'd say!

    mark
    --

    If you want to make an apple pie from scratch, you must first create the universe. -- Carl Sagan
  5. Quick Learning by jeks · · Score: 5, Informative

    Learning C as your first language, without any prior computer experience may not be the most clever thing to do. Programming C efficiently, correctly and clearly is best achieved by first understanding computer architecture and programming concepts.

    A higher level language provides the abstractions necessary to accommodate "logical thinking" as opposed to a full understanding of say memory management and system I/O. Also, C is quite an orthogonal language in that it supports many awkward combinations of features and constructs. If you are not careful to make your source text clear and readable, debugging even your own code can be oh so cumbersome.

    Hence, perhaps reading a book such as "Computer Architecture: A quantitative Approach" by J. Hennessy and D. Paterson is a sensible step towards learning C for the beginner.

    1. Re:Quick Learning by yatest5 · · Score: 3, Interesting

      Learning C as your first language, without any prior computer experience may not be the most clever thing to do. Programming C efficiently, correctly and clearly is best achieved by first understanding computer architecture and programming concepts.

      A higher level language provides the abstractions necessary to accommodate "logical thinking" as opposed to a full understanding of say memory management and system I/O. Also, C is quite an orthogonal language in that it supports many awkward combinations of features and constructs. If you are not careful to make your source text clear and readable, debugging even your own code can be oh so cumbersome.


      I would totally disagree. Learning a higher-level language, like Java, first, will mean you miss out on learning all the basic stuff you would pick up in C which will stand you in good stead if you ever need to pick up other languages quickly.

      --
      • Mod parent up! [a] by Anonymous Coward (Score:5) Thurs, June 31, @13:37
    2. Re:Quick Learning by Uberminky · · Score: 5, Interesting

      I'd tend to agree with you on this one. I understand his points, and perhaps another language should be used at the very beginning. I started out on HyperTalk (the scripting language of HyperCard -- that was the coolest toy I had as a kid), learned Pascal (because that was what they taught)... and then FINALLY learned C. This may sound silly but it was a breath of fresh air to me. Everything made sense, everything could be explained in terms of this. The special cases were all gone. Sure, some things were more work, but I learned so much from C in that 10th grade class. I really feel it has helped me have an edge over many of my college peers. Heck, I would've loved to learn assembly language first. I'm having a blast with it now, in embedded systems. It's doing the same thing that C once did for me, simplifying it down to what's REALLY going on, deep down on the metal, so that I truly understand it. One architecture may go out of date, but you can learn just as much from PDP-11 assembly as you can from Lisp today, they're just in different fields. My fifteen cents.. ;)

      --

      The streets shall flow with the blood of the Guberminky.

  6. Re:Why are people still using a 30 year old langua by pizen · · Score: 3, Insightful

    It seems that Dennis Ritchie was so besotted with A and B that he forgot to take out the trash.

    If the computing industry had any sense, it would have switched to Java 10 years ago. Why hadn't it? Inertia!


    Speaking of taking out the trash...I prefer to say when garbage collection occurs. I don't get that control with Java like I do with C.

  7. here's a good beginner book on C by ForsakenRegex · · Score: 4, Informative

    The best book for C beginners I've ever come
    across is _A Book on C_, by Al Kelley,
    and Ira Pohl. I've recommended it to quite a
    few beginners and they've all said it was an
    easy and very informative read.

    --
    "A man talking sense to himself is no madder than a man talking nonsense not to himself."
  8. The Art of Writing by Alien54 · · Score: 3, Insightful
    The Art of writing and education is difficult in its own right, and not everyone knows how to put things together. Often you have to correctly analyse what concepts are fundamental to the understanding of more complex concept.

    As an example, I can recall a man who came into the store where I was working, and who asked me how much "virtual memory" cost.

    Besides trying not to laugh there was the problem mentioned above.

    The fundamental concepts missing were the concepts of "memory" and "virtual", along with a larger mental model to enable the average person to organise the concepts into something useful when dealing with computers. [The usual mental model I use for beginners is one of a computer = your information factory. Hard drives = warehouse, etc.]

    It is possible to arrange things inthe manner of " Gradus ad Parnassum " (graded steps)

    Without proper technique in this area, It is very easy to make a bloody mess of it. It is a skill in its own right, separate from knowledge of the area to be taught in the first place.

    --
    "It is a greater offense to steal men's labor, than their clothes"
  9. Tools of the trade. by DCram · · Score: 3, Interesting

    When you walk into HQ or Home Depot have you ever asked yourself why are there so many tools that do about the same job? There is always the right tool for the job. This is the same as it is in the programing world. I have heard people in this thread say why use C. Because if its the right tool to get the job done then use it. Don't get so caught up in one language, even a new one, that you make yourself a dino.

    A good C book is always a great find. I find myself going through kernel code or drivers or as of late the netsnmp code going hmmm.. I've seen this before but exactly what is going on.

    Refrence material is always good..no matter what.

    What I would love to see is a thread on what books most coders have found to be the most useful, what they have on there shelves.

    I love reading the reviews that say the book is good but not really worth my time.

    --
    If I were only smart enough to accomplish the things I dream about.. Or maybe too dumb to care.
  10. Re:Why are people still using a 30 year old langua by pizen · · Score: 4, Informative

    So what you're saying is that you prefer a language that has NO MEMORY MANAGEMENT to one that does?

    A good programmer can manage memory without the help of the runtime environment. There's a certain pride in being able to program with no memory leaks.

  11. Just for fun... C is a hoax? by spaten-optimator · · Score: 5, Funny

    An old april-fools joke, this snippet will give you a good chuckle at the expense of C:

    "We stopped when we got a clean compile on the following syntax:

    for(;P("\n"),R--;P("|"))for(e=C;e--;P("_"+*u++/8)% 2))P("| "+(*u/4)%2);

    To think that modern programmers would try to use a language that allowed such a statement was beyond our comprehension!"

    Also check out shooting yourself in the foot in various programming languages.

    --

    --
    Disclaimer: The above statement probably includes half-truths, because real truth is too complicated.
  12. Re:don't waste your time by elefantstn · · Score: 5, Funny

    Not only that, but pulling a dog-eared, bookmarked, highlighted copy of K&R off your bookshelf has the panty-removing power of playing your band's seven inches or flashing the keys to your '57 Corvette.

    --
    If it ain't broke, you need more software.
  13. Re:Why are people still using a 30 year old langua by blackwings · · Score: 5, Informative

    Reasons to still use C (at least sometimes):

    1. It is the native language to most operating systems API (*nix, MS-*).

    2. It is the language most third party librarys and code is written in.

    3. It is the language a lot of old code is written in.

    4. Interfacing other languages with libraries or APIs written for C is never as easy as the documentation says it is and issues may slow down development time significantly.

    5. It is the only widely used standardized all purpose language that is available to all platforms.

    C++ - is hardly standardized (most compilers still does not come close to the ANSI-C++ standard).
    ADA - Is not widely used.(unfortunately)
    Java - Is not an all purpose language.

    6. It is a very elegeant and consistent language (unlike C++).

  14. Re:Why are people still using a 30 year old langua by jaoswald · · Score: 4, Insightful

    What makes you think dynamic memory management in C is efficent?

    Just because "malloc" and "free" each fit on one line of code doesn't mean they are fast or efficient. In particular, if your memory arena gets seriously fragmented, the performance of these routines can get worse and worse over time.

    As opposed to a genuine generational garbage collector, for which the performance stays relatively consistent.

  15. Re:Why are people still using a 30 year old langua by Snowfox · · Score: 3, Insightful
    Why are people still using a 30 year old language?
    Why are people ignoring 30 years of code maturity?
  16. Where to look for good C and C++ book reviews by Anonymous+Brave+Guy · · Score: 3, Informative

    You might try the Association of C and C++ Users web site.

    --
    If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
  17. Get rid of C! by Tom7 · · Score: 5, Insightful

    Goodness, this is an awfully empty review. Except for the comment about the author's native language (which humorously is followed up by an awkward if not ungrammatical sentence from the reviewer), this whole review could be applied to practically any programming book! What sets this book apart? If nothing, then why review it?

    Anyway, the real reason I clicked on this article is because I just love a C debate. Since there's hardly anything to talk about with regard to the review, let's get to it!

    Here's what I say: outside of the low-level systems crowd, C should die. We should *not* be teaching beginning programmers C or C++. C should not be the "default language" of computer programming.

    Today, efficiency is no longer the primary concern about software. It has been ousted by robustness and ease/cost of development (modularity and reuse). C is awful for robustness (the language lets you "get away" with anything you want, though those things are seldom what you want in application software), and even worse for modularity and re-use. Modern languages, or even quasi-modern languages like Java, are far better than C for robustness and ease of development. They even win on some points which are typically seen as less important than efficiency: portability, elegance, etc.

    Finally, the efficiency of high-level languages is comparable (though not as good as) C. Compiler technology is improving somewhat, as well. But since developing and debugging take less time, you have more time to optimize your program (if necessary), so I am not convinced that this is really a big deal. Yet, even if I need to concede the efficiency issue, I still believe modern languages beat C overall.

    I'll be glad to argue about that stuff, but today I have a different point to make. C is also holding back the progress of other computer fields. Let me give you an example. My friend is working on compilers that compile high-level languages (to them, C is a high-level language) down to circuits. Here, discovering data parallelism in the code is probably the most difficult problem. Of course, the same issues arise in compiling to architectures like the IA-64 or even P4, where in order to get best execution speed, the compiler needs to figure out what instructions can be executed in parallel.

    When they compile C, they need to look for common idioms (certain patterns of for-loop use), then analyze them to extract the parallel algorithm. For instance, this simple C loop adds k to every integer in an array a of size s:

    for (int i = 0; i < s; i++) {
    a[i] += k;
    }

    The idea is that the compiler should be able to produce a circuit that does all of the adding in parallel, on silicon. Since you all probably grew up on C, this seems like the totally natural way to write that code. In fact, it is short and it is straightforward. Unfortunately, it is less straightforward to a compiler. The compiler needs to prove to itself that the for loop can be parallelized -- what if the programmer changed k or a or i in the loop body? The C code actually says to run each loop iteration sequentially.

    Of course, compiler writers have gotten pretty good at catching this particular idiom, but when the code gets more complicated (especially when the compiler needs to do alias analysis), it is not so good.

    The chief problem here is that the programmer is unable to effectively communicate his parallel algorithm to the compiler. The programmer takes something in his mind "add k to all elements in the list", sequentializes it for C "for (int i = 0 ...", and then the compiler has to *undo* this sequentialization to produce the parallel code. In the process of translating, some information is always lost.

    Now look how this code would be written in SML (a so-called "modern language"):

    Array.modify (fn x => x + k) a

    (fn x => x + k) is a function expression (SML lets you pass around functions), and Array.modify simply applies the function to every element in the array. Here, the compiler can very easily tell that my operation is parallel, because I used Array.modify! The code is also a bit shorter, and I also think that this code is a lot clearer. That's subjective, of course. BUT, I hope you will agree that for this example, the SML code is closer to what the programmer means, and easier for the compiler to understand.

    Anyway, perhaps some of you will say that this particular issue is not a problem, or that it is already solved (I would like to hear the solution!). I merely mean to propose an example of a theme I have been observing over the past few years in many areas of computer science. Computer programming is about communicationg with the compiler or machine in such a way that it is easy for the human to create code, and easy for the machine to understand it. C was never particularly easy for a human to create (though we have become accustomed to it), and though it was once easy for a compiler to understand, this is becomming less and less true. When the language is neither optimal for humans nor optimal for compilers, doesn't that mean that something needs as change?

    1. Re:Get rid of C! by Jimmy_B · · Score: 3, Insightful

      Your post is definitely a troll, but since you immediately admit and justify it ("Since there's hardly anything to talk about with regard to the review, let's get to it!") I will respond anyways.

      I'll start my argument with an anecdote. There is one particular C++ program I was writing, not atypical, and not a particularly difficult problem computationally. I was programming on my AMD Athlon 1400MHz, a fast computer by any reasonable standards, and found that it wasn't running as fast as I'd like. I profiled it, and found the functions to blame were operator overloads (called very frequently) on a class coord, which looked something like this:
      friend coord operator+ (coord a, coord b) { return coord(a.x+b.x, a.y+b.y); }
      Spot the error on that line. Now, ask someone who's never programmed in C before to spot the error. Give up? It's the passing by value, which prevents the compiler from inlining the function; the correct way to write that function is:
      friend coord& operator+ (const coord& a, const coord& b) { return coord(a.x+b.x, a.y+b.y); }
      If not for my experience programming in C, I never would've realized that.

      It is my observation that people who are taught to ignore C, and start immediately with an object-oriented language such as C++, <B>never</B> learn low-level concepts such as inlining or pointers, and never learn to truly understand what it is that they're writing. I say that the best way to learn and properly appreciate the "right way" of doing something is to first do it the *wrong way*, in a project that doesn't matter for anything. I have debugged pointer spaghetti, written code with dozens of meaninglessly named global variables with no comments, written procedural code, and had I not done these things, I wouldn't know why it is important to name variables intelligently, to use object orientation, or to use pointers carefully. You tell someone to comment their code, and you get lines line this:
      a=b; // Copy b into a
      The only reason the comment is there is because they were taught to always comment their code, to comment every line, etc. On the other hand, someone who's dealt with uncommented code before would put useful comments where they need to be.

      I agree with you that C should not be used in production code where it can be avoided (that is, areas other than systems and embedded programming). However, I strongly believe that people should always learn and master C before learning higher-level languages. If the only reason you use classes is because you were taught that that's how to write clean code, then you're not using them correctly. On the other hand, if you're using classes because you wrote in C up to the point where you encountered a problem that required inheritance or polymorphism, then you're using the feature for the right reasons.

      Your example, by the way, in which a loop that increments elements of an array is parralelized in hardware, is actually simpler than you think. The compiler first performs loop unrolling (a very, very old idea), then analyzes the code blocks to see that they don't work with the same data, and parralelizes them. Your particular example implies that the only real way to solve parralelism is to define parralel functions and human-solve them; this clearly violates the distinction between language and library, and doesn't really help. Besides, in your case example of compiling high-level code into hardware, I could come up with far more examples where object orientation hurts rather than helps. OO hides all of the overhead, promoting huge bloat which, while not a problem in software, is fatal in hardware.