HN Books @HNBooksMonth

The best books of Hacker News.

Hacker News Comments on
Learn C the Hard Way: Practical Exercises on the Computational Subjects You Keep Avoiding (Like C) (Zed Shaw's Hard Way Series)

Zed Shaw · 120 HN points · 1 HN comments
HN Books has aggregated all Hacker News stories and comments that mention "Learn C the Hard Way: Practical Exercises on the Computational Subjects You Keep Avoiding (Like C) (Zed Shaw's Hard Way Series)" by Zed Shaw.
View on Amazon [↗]
HN Books may receive an affiliate commission when you make purchases on sites after clicking through links on this page.
Amazon Summary
You Will Learn C! Zed Shaw has crafted the perfect course for the beginning C programmer eager to advance their skills in any language. Follow it and you will learn the many skills early and junior programmers need to succeed–just like the hundreds of thousands of programmers Zed has taught to date! You bring discipline, commitment, persistence, and experience with any programming language; the author supplies everything else. In Learn C the Hard Way , you’ll learn C by working through 52 brilliantly crafted exercises. Watch Zed Shaw’s teaching video and read the exercise. Type his code precisely. (No copying and pasting!) Fix your mistakes. Watch the programs run. As you do, you’ll learn what good, modern C programs look like; how to think more effectively about code; and how to find and fix mistakes far more efficiently. Most importantly, you’ll master rigorous defensive programming techniques, so you can use any language to create software that protects itself from malicious activity and defects. Through practical projects you’ll apply what you learn to build confidence in your new skills. Shaw teaches the key skills you need to start writing excellent C software, including Setting up a C environment Basic syntax and idioms Compilation, make files, and linkers Operators, variables, and data types Program control Arrays and strings Functions, pointers, and structs Memory allocation I/O and files Libraries Data structures, including linked lists, sort, and search Stacks and queues Debugging, defensive coding, and automated testing Fixing stack overflows, illegal memory access, and more Breaking and hacking your own C code It’ll Be Hard at First. But Soon, You’ll Just Get It–And That Will Feel Great! This tutorial will reward you for every minute you put into it. Soon, you’ll know one of the world’s most powerful programming languages. You’ll be a C programmer. Watch Zed, too! The accompanying DVD contains 5+ hours of passionate, powerful teaching: a complete C video course! If you purchase the digital edition, be sure to read "Where Are the Companion Content Files" at the end of the eBook to learn how to access the videos.
HN Books Rankings

Hacker News Stories and Comments

All the comments and stories posted to Hacker News that reference this book.
Apr 22, 2015 · 37 points, 17 comments · submitted by hikz
kasabali
http://hentenaar.com/dont-learn-c-the-wrong-way
jacobolus
This critique is completely incoherent. I read the first half, and I still have no idea what the author’s point is.

Most of it seems to be pedantic complaints stemming from the author’s overly literal interpretation and incomprehension of Zed’s sometimes ironic writing style.

youngtaff
The reviewer fails to understand Zed's approach to teaching…

His approach is that new developers need to get something that works so the reward of it working is motivating before you explain how/why it works to them.

Based on my experiences with my kids I think it's a perfectly valid approach - an led that turns on motivates them to understand why it turns on.

yarrel
Author writes review criticising book for misleading readers.

Adds later note inline to explain that he really does know what he's talking about, and any accusations that he doesn't are either pedantic or comprehensively challenged.

Fails to reflect on how this may relate to the subject of the review.

cushychicken
This guy encloses about 3 valid criticisms (the one about makefiles foremost among them) in a huge, dogmatic screed of nitpicks that he just assumes people will read and think "he's wrong he's wrong he's WRONG" about Zed.
pan69
I think the article of this author is pedantic. The articles written by Shaw will show how to create programs with a specific language such as C, Ruby or Python and the C version is, of course, no substitute for the K&R book.

The K&R book tells you all the ins and outs of the C language. The Shaw article gives you a practical way to build a program with the C language.

I would assume that an experienced programmer, such as the writer of this article seems the be, would understand this.

saboot
Is there a table of contents anywhere? I remember wishing he finished the "Let's Make a Virtual Machine" section at the end of the html preview of this book. It was never updated which was disappointing as it sounded really interesting.
comex
Of course this comment thread is (judging by the comments so far) going to be mostly about whether Zed Shaw criticizing old fashioned C is right or not or whether the criticizers are right or whatever. Oi... against my better judgement, I'm going to call out a few relatively objectively objectionable points in the book (which are still there, as opposed to the removed K&R chapter):

- He repeatedly states that processing an invalid C string can loop infinitely, but it can't - except in extremely rare cases on exotic systems, which seem to be the exact opposite of what he's going for. In reality it will always crash (unless being exploited by an active attacker!). The hentenaar.com post already notes this, but this instance of him being objectively wrong is buried among a huge number of more stylistic and debatable points.

The error is not a big deal, since neither looping infinitely nor crashing is desirable, but I can't help but think it demonstrates the author's lack of experience in what he's supposed to be teaching.

- Also wrong: "The source of almost all bugs in C come from forgetting to have enough space, or forgetting to put a '\0' at the end of a string." Forgetting to null terminate is a newbie mistake. A claim that almost everything that can be incorrect about a C program comes from a buffer overflow seems obviously spurious, so I'll give the benefit of the doubt and assume he's referring to security problems. In that case, some bugs involve straight buffer overflows, but a good fraction of real-life security bugs involve other things like integer overflows and use-after-free.

Also not exactly a big deal - perfectly sufficient to worry about overflows just because they account for many bugs, rather than almost all - but it seems myopic with respect to real world code.

- "In fact it's so common and hard to get right that the majority of good C code just doesn't use C style strings." I guess it's technically subjective what counts as "good", but most C codebases use C strings to some extent, so this is pretty misleading.

As one example, OpenSSH, despite being very carefully written code that uses a safe buffer API for the low level protocol manipulation, also uses C strings all over the place. As another, Linux is generally considered reasonably high quality, and it makes no effort to avoid C strings. I think you'd have a hard time making a long list of well-known C programs that do use alternative string libraries exclusively. (Note: this has no bearing on whether or not doing so is a good idea.)

- "In C, there's not really a 'boolean' type" - there has been since 1999; a lot of code doesn't use it, but since this is aimed at modern C, are you really not even going to mention it?

- Type Conversion section doesn't mention (or incorrectly describes, I can't tell which) the "integer promotions"; these are an awful feature and relying on them is awful, but a manual for how implicit conversions are done shouldn't have an incorrect algorithm!

comex
Small correction to self: when I said "always crash" I meant if it doesn't stop itself by finding a zero byte that happen to be in memory; the exception is a rather obscure exploit scenario where an attacker takes control before you get to that point. But the most common case is of course that it finds a zero which happens to be within a few bytes of the end of the buffer, because zeroes are common.

Point is, it won't infinite loop.

cushychicken
This is way more coherent than Hentenaar's screed; thanks for posting it, I've always had a hard time understanding the points articulated against LCTHW.

I think all of the points you've mentioned are correct - Zed's said some stuff that isn't to-the-letter accurate. I guess the reason people get up in arms (wrongly, IMO) about pointing these things out is the worry that these details he got wrong will obscure the bigger picture of his work. I think it's a pretty silly thing to freak out about; Zed's taken a programming language that's frequently seen as daunting and difficult to learn and made it fairly accessible for a new/newish programmer. So what if he missed or misinterpreted a few finer points?

I guess that's why Zed Shaw comment threads end in flame wars on HN - half of the people are pissed at what they view as attempts to besmirch their teacher, and the other half are watching the first half get up in arms about what's essentially a code review and thinking "Jesus, you must be shitty programmers because of how personally you're taking this".

Just my opinion. Mileage may vary. :)

coldtea
>Let me start by saying that unlike Mr. Shaw, I am not a writer. I'm an engineer.

Such BS ad-hominen are not really need. As for the review, the first 12 paragraphs are empty blathering, and then we have empty criticisms that misunderstand the whole logic of the book. For example:

>So, finally printf() gets introduced. The author fails, in my opinion to explain what it actually does. This has the reader using format strings before even explaining (even briefly) what a format string is. This has become a repetitive theme in this book, and if I were a novice, I'd find it very confusing.

The whole idea of the book is that you learn by doing and repeatition first (like a kid does when learning to speak), and then you're told the concepts and details.

mateuszb
It's not ad-hominem BS.

http://zedshaw.com/about/ "I am Zed A. Shaw and I write for fun and profit."

That is he is a writer, in a world where logic and reasoning applies.

explosion
Is there any reason why one can't be both a writer and engineer simultaneously?
wyclif
I don't think he meant that the "I am not a writer" part was BS (obviously Zed is a writer; the OP is a link to his book), but rather that this is posturing instead of an argument.
JadeNB
I'm sorry for a stupid question, but from where are you quoting? As of 19:53 on 2015 April 22, the link seems to be to an Amazon page for Shaw's book, with no customer reviews.
sciurus
They are quoting from http://hentenaar.com/dont-learn-c-the-wrong-way
andrewstuart
Also, Zed Shaw isn't just "a writer", he's known for writing some really fine applications.
Nov 30, 2013 · 83 points, 24 comments · submitted by shawndumas
DonGateley
All you need is K&R, honest.

C is a very simple language. I learned it from K&R in the '80s in an office in a building in a corn field on a back road halfway between Rockford, Il and Belvidire, Il. I went on to hire and assist eight others in acquiring it and then employed them to write, along with myself, a successful machine tool controller of serious sophistication employing a three way tightly coupled Mot 68010 MP system (using bus fault recovery to resolve address collisions) of my design. Not bragging, really, just being dramatic about what you can accomplish starting with just K&R.

nzp
Do note that Zed actually discusses in this book (at least in the online version) why it might not be the best idea to learn C from K&R today. His basic argument, IIRC, is that the examples in K&R are very bad when it comes to writing modern C. Sure, you'll learn the language in a formal sense, but K&R is hardly going to prepare you for the reality of C programming.
DonGateley
I'm curious what reality he considers missing from K&R.
nzp
"Reality" was my word, I tried to condense the essence of his argument. That chapter is online[0] and as far as I see, only the "deconstructing" exercises part is missing. I've read it some time ago, so I'm not sure anymore if I would agree with everything he said because I don't remember every argument (but I don't feel competent enough about C to strongly comment either way anyway), but what he says in "Overall Critique Of Correctness" seems pretty reasonable.

[0] http://c.learncodethehardway.org/book/krcritique.html

DonGateley
I'd like to add that this was not only before the public Internet but almost before the PC. :-)
rhizome31
Your statement assumes that one already has access to a copy of K&R. For those who don't, there's no reason not to start with a cheaper, more recent book.
danieldk
Except that there are so many K&R copies floating around that it's easy to get a cheap second-hand copy. E.g. my local Amazon (.de) sells copies starting at 15 Euro.

K&R is really the definitive C book.

ryanobjc
I find the C backlash to the excesses of C++ fascinating.

On the flip side, I wonder how people deal with 'programming in the large' with C - other than 'just be really really careful'

ninjin
> I find the C backlash to the excesses of C++ fascinating.

I whole-heartedly agree. Something that blew my mind back in undergraduate school was tree.h by Niels Provos, [1] which is a complete key/value-type agnostic Red-black Tree [2] in a single header file. Just recently when re-learning C I stumbled upon klib [3] which has a similar take on generic programming by "abusing" the preprocessor.

If I am allowed to side-track, I found "C The Hard Way" to be a good resource when re-learning C. I also had a lot of fun with "Expert C Programming", although it is a bit dated. I highly recommend it once you have a grasp of the language basics. I have heard good things about "21st Century C", but I am still wondering what other good resources there are out there.

[1]: http://svnweb.freebsd.org/base/head/sys/sys/tree.h?view=mark...

[2]: http://en.wikipedia.org/wiki/Red%E2%80%93black_tree

[3]: https://github.com/attractivechaos/klib

None
None
noselasd
You don't always need preprocessor tricks to generate a special purpose red-black tree, you can use an intrusive variant like this: http://cgit.osmocom.org/libosmocore/tree/include/osmocom/cor.... This works together with the container_of macro: http://stackoverflow.com/questions/15832301/understanding-co...

In similar spirit, the linked list variant: http://cgit.osmocom.org/libosmocore/tree/include/osmocom/cor..., though the macros in sys/queue.h are also useful for linked lists.

shadowmint
For better or worse an alpha copy of the sort of content for the book is here, for people who might want to find out a bit more about what the style/content/etc. is like, before getting the final book:

http://c.learncodethehardway.org/book/

ProAm
Such a good read, I wish he'd use line numbers in his code syntax blocks. Its so hard to read and re-reference without them. For those who cant see well it helps a lot, and most modern IDEs/text editors line number for you as well.
saraid216
That's odd, since in Learn Python, he pretty specifically goes out of his way to make sure the student enables line numbers... specifically for these reasons.
ldonley
Always happy to see another Zed Shaw book, especially after seeing how nice and helpful he is to others on HN. If this is anything like Learn Python the Hard Way then you should definitely check it out if you are trying to learn C.
chatmasta
Funny how his timing works...
lampington
Oh come on, seriously? He's a fantastic coder, a great educator and a decent guy in what he does. Sure, he's abrasive and runs people up the wrong way. But let's not read stuff into timing.
doktrin
Excellent. There are relatively few books I'm tempted to pick up in paperback, but this would be on my short list (despite having worked through most of the material available online ~6 months ago).
donatzsky
Slightly OT:

Can anyone recommend something similar for Java (Android specifically)? The tutorials I have found so far seem to assume I'm either a complete imbecile or have a CS degree.

rquantz
This is exciting. I've been waiting to see how he filled out the later chapters for a while now, and presumably this means they're done, or at least will be by May. I want to see that tiny virtual machine get built!
lobo_tuerto
Hope he publishes somewhere an .epub version of them (all his books).
alexpopescu
I haven't read any of Zed's book and Amazon doesn't have a decent number of reviews, so I was wondering if someone could provide the shortest "why should I get this book"

thanks

cenhyperion
read the version he provides freely online and see if you like it: http://c.learncodethehardway.org/book/

I learned to write python (and program) through Learn Python the Hard Way.

akulbe
Ordered. Looking forward to this.
sivers
Full-view (non-mobile) Amazon link: http://www.amazon.com/dp/0321884922
HN Books is an independent project and is not operated by Y Combinator or Amazon.com.
~ [email protected]
;laksdfhjdhksalkfj more things
yahnd.com ~ Privacy Policy ~
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.