
Learn C The Hard Way by Zed Shaw - shawndumas
http://www.udemy.com/learn-c-the-hard-way/
======
waffle_ss
I was wondering how this compares with or compliments K&R, when I came across
[this section][1] of the book that seems to slap it in the face. Here's a
section from the second paragraph:

 _You see, "K &R C" is actually riddled with bugs and bad style. Its age is no
excuse. These were bugs when they wrote the first printing, and the 42nd
printing. I hadn't actually realized just how bad most of the code was in this
book and recommended it to many people. After reading through it for just an
hour I decided that it needs to be taken down from its pedestal and relegated
to history rather than vaunted as state of the art._

This seems a bit hyperbolic to me... I just read K&R several years ago during
school (could definitely use a re-read) but remember absolutely loving it for
the combination of brevity and density of information conveyed. I'm not much
of a C programmer though so I don't really know. Could a modern C programmer
respond / elaborate?

[1]: [http://c.learncodethehardway.org/book/learn-c-the-hard-
waych...](http://c.learncodethehardway.org/book/learn-c-the-hard-
waych55.html#x62-31400055)

~~~
Jabbles
It's a bit like claiming memcpy() is bugged because it can crash your program.
Well, true, it is good style to program defensively against memory
corruptions, buffer overflows etc, and in that respect K&R may teach students
bad habits.

I think it's a bit much to say that it should never have been written like
that, as at the time people knew so much less about building complex projects,
sources of error and defensive programming.

Keeping a book up to date takes a lot of effort, as I'm sure Zed (npi)
appreciates. It's an old book, it has warts. As you stated, the density of
information was what many people like about the book, so any replacement for
it will have to replicate that. I don't think the criticism is unfounded
though.

~~~
zedshaw
memcpy is just fine because it has a size parameter. I think you mean
strcpy(), which does cause defects.

~~~
Locke1689
Nah, memcpy shouldn't exist (just not for buffer overflow reasons). memcpy is
there because someone got their knickers in a twist over possibly being a few
cycles faster than memmove, even though the chances that actually matters is
tiny, while the chances that you'll accidentally use memcpy when your memory
overlaps is much larger.

~~~
jheriko
actually that justification for memcpy is quite poor. usually, performance
wise, it is quite easily beatable once you start using the hardware. most
implementations I've seen loop byte copies in the most naïve way possible...
almost every architecture supports 32-bit copies, most support more... :)

incidentally I've saved some .2-.8ms per frame in a "AAA" (I use the term
loosely and with disgust) game title by replacing compiler generated
assignment operator in one struct with an explicit 128-byte copy. copying
individual bytes is slow, and the compiler is never as sufficiently smart as
people claim.

in analagous cases involving memcpy, the fact that memcpy is not memmove saves
much less than actually copying the data in a way that squeezes everything out
of the data buses. :)

~~~
Someone
_"almost every architecture supports 32-bit copies"_

How much of that was true at the time that function was created?

Also, on 'just use memmove': it would not surprise me if ancient Unices used
memcpy instead of inlining it to copy really small buffers (such as 14-byte-
max filenames), not for speed, but for the byte savings (even if singular
'byte' is the correct way to phrase that). With small buffers, the overhead of
that 'if' can become substantial.

------
zedshaw
Just a warning to everyone, like the book this course is in development as I
write the book. It's covering a lot of the chapters, but I have to go back and
clean up some videos and do the final ones. That's why the price is low for
now.

~~~
mhartl
What's your method for making the ePub version of your books? I'm considering
writing a custom program for my own stuff, but I'd love to be able to use
something off the shelf.

~~~
zedshaw
I'm ditching ePub. It's a crap format that has a bewildering number of options
and it seems every viewer wants to implement some different subset of them.

From now on, it's PDF and HTML only.

~~~
mhartl
Glad to hear it. When people ask me about ePub/Mobi, I tell them that both
formats are broken and that if I ever produce them it'll only be as a stupid
marketing gimmick.

What we really need is a format that works across different devices. If only
there were a _portable document format_ that solved this problem...

~~~
tjoff
Yeah, because PDFs work really great on devices of different screen sizes.

Also, the author should stop promote the epub version if he won't do it.

~~~
mhartl
This is a limitation of the device, not the format. Why do people expect to be
able to read heavily formatted books on every device they own? For books made
up mostly of natural language text, this might be a reasonable expectation,
but technical books have a different set of design constraints that make them
ill-suited to general e-readers.

~~~
tjoff
_This is a limitation of the device, not the format._

No it's not. The kindle works fine for programming books, I'm currently
reading Bjarne's "The C++ Programing Language" on my kindle, on PDF actually.
The book itself lies on my bookshelf but why would I bother to open it?

The PDF isn't tailored for the kindle but it has wide enough margins so that
when you crop it it works quite well on the kindle. The kindle is not the
limitation nor the problem.

The problem is rather the crippled format that you get in a fullsize PDF. What
exactly are you going to read it on? Print it out? (seriously?). On your
monitor? Not really... On your tablet? You're joking right, reading a book on
a glossy LCD?

Having a book as a PDF is quite useless for other than using it as a
reference.

Now I don't know about any potential issues with epub/mobi, and honestly I
couldn't care less in this case. The site mentioned (and still does) that an
ePub will be available and if so I kind of expected an ePub version of it, in
my eyes that was an incentive to take the course.

If that isn't going to happen an ~A5 PDF will work great too, since there
actually exist devices that you can read it on comfortably.

And I kind of have a hard time to see why the book, as it is portrayed in the
HTML-version wouldn't be able to work as an epub - but OK, if that's the case
(or if epub truly is just a mess) that's surely not the case for a portable-
device-friendly-PDF.

Also, it really cracks me up to see someone talk about broken formats and in
the same post make an argument for PDF.

------
aseembehl
In case one does not want to spend $29, the free HTML book [1] (currently in
beta) is good enough. I have been following along the book, and can vouch for
it. It is a great way to learn to code in C.

[1] <http://c.learncodethehardway.org/book/>

EDIT: By posting the link to the book, I by no means meant that the videos are
redundant. I would love it if more people en-roll for Zed's Udemy course and
support him.

~~~
johnohara
How much $$ have you spent on lattes reading his free book?

Books, videos and course materials don't just happen because we say so. Real
people create this stuff.

~~~
benmanns
It amazes me that people invest 20 hours in reading a book and complain about
the price. If we assume roughly $40/hr for a $80k programmer, this is about
$800 worth of time you're investing. Does a "hard" investment of $29 (4%)
really make that big of a difference?

~~~
shadowfiend
I always use “let's assume roughly X/hour” as a joke.

You don't get paid for your spare time, except in opportunity cost. If someone
applies 20 hours of their time at work, then yes, that's pocket change. If
they apply 20 hours of their time at home, that's not time that they'd get
paid for anyway, so the analogy is as foolish as the claim that every pirated
copy of a movie would have been bought were it not for pirates.

Instead, I'm choosing between 20 hours of reading a book and maybe 20 hours of
watching television (for example), which costs the electricity that the
television consumes (since the cable or internet is paid for already). I
suspect you'll find 20 hours of TV will cost less than $29. Or maybe it's 20
hours of running over the course of a couple of weeks. That's free, except
maybe for the cost of the water to rehydrate. That's probably cheaper than
$29, too. If you want to do the analysis in terms of how much it will earn you
in the future, that's also valid I guess. But it complicates things, since
it's hard to quantify how much the relaxation you get from watching TV or
destressing from running is worth.

Let me just say, I don't think people should complain about the price of a
good book when it's <$50-100 (depending on material). But the X/hour analogy
only works if you're taking work time, and then many companies will often be
willing to refund you that money anyway.

Last note: this isn't $29 for a book. It's $29 for a video course (though
admittedly a non-HTML version of the book is thrown in at the end). The book
itself is available for free, which is all that the OP was pointing out.

~~~
benmanns
True, but by working for "roughly X/hour" you've established that the typical
exchange rate for your time is roughly X/hour. If I were to ask you to do some
work for my during your off time, I would have to pay about X ± X/2 depending
on how you guarded your time. So what if someone only values their time at
X/4? That's still $200 worth of spare time.

~~~
shadowfiend
That's fair, if we're continuing a monetary analogy (which I did do).

My spare time is worth happiness/distraction to me. Not money. I will confess
that in that particular regard, I may differ from some, or perhaps even most,
others.

------
antirez
I just scanned through the free HTML book and this looks definitely a good
start for a modern "get started fast" book about C: everything is important
about the language seems to be covered. Good work.

------
skrubly
I'm excited - Learn Python the Hard Way completely jumpstarted me into what
has become a large internal django site, and I refer back to it often. I
really enjoy python, and I thank Zed for the straightforward aproach.

So even though I love python I want to see if the same technique can introduce
me again to C, a language I never felt comfortable with.

~~~
zedshaw
Try going through the HTML version, and drop comments when you hit problems.
That'll help me make the book solid.

~~~
esbwhat
Are guest comments ever going to be an option? I don't really want to make a
disqus account. I understand if not, but I figured I'd ask anyway.

~~~
zedshaw
No, I'm fully blocking and moderating comments. They are for serious students
who need help, not drive-by netizens. In the past I had them open, but after
the first two hits by HN or reddit I had to lock it down so that students
wouldn't get thrashed.

~~~
esbwhat
FWIW i signed up to your udemy course, but I don't particularly feel like
making a disqus account to also comment on the book, that's what's bothering
me. I guess I will just abstain from commenting though, it's fair enough.

------
2mur
What I really like about LCTHW (after reading K&R and then just _not doing
anything with it_ ) was starting you out using the tools and best practices
right from the beginning. Make and valgrind up front. It got me over the hump
of syntax&language --> actually using.

------
mitchi
I disagree with your disdain for IDEs... I hope that you are not totally
misleading the people who will learn from your book because learning how to
use the capabilities of Visual Studio or any decent IDE is very valuable. How
are they going to debug complex graph data structures in their CS class if
they don't have a great debugger? How are they going to understand the power
of intellisense in modern programming? How are they going to learn about
compiler flags without getting a headache? How much time are they going to
waste compiling and linking with the commandline?

I like the no-copy-paste and straight notepad approach trust me. It works for
everyone, it's a solid way to get these things into your brain. You need to
write code, there's no way around it. But to tell people to never use IDEs
because they are bad and they make you a bad programmer is BULLSHIT.

~~~
zedshaw
IDEs are bad for you. It's much better to simply use a real programmer's
editor that you can craft into being what you need. In fact, I can usually
take vim plus cscope, exuberant ctags, and ack and demolish any code base you
throw at me. Similar with emacs and other power editors.

IDEs are usually useful if you're stuck using them to build GUIs or use
specialized build tools they require.

~~~
Tomis02
Please dear wizard, here's a list of requirements for a fellow programmer that
he can currently do with Visual Studio and wants to do the same with vim:

\- find in files (in vim, not in bash)

\- replace in files

\- rename symbol (uh-oh...)

\- quick open file in project (visual assist feature)

\- list of files in project (not in directory)

\- build system (something easy to use, not that make bullshit)

\- go to declaration/definition ( sometimes I get a list of 30 matches from
ctags, so I would like something that actually works )

\- view call hierarchy (callers, callees)

\- code completion (something that works and is easy to use, like in visual
assist)

\- watches

\- breakpoints in disassembly

\- step into disassembly

\- memory view while debugging

\- edit & continue

\- memory (data) breakpoints

We're talking about large C/C++ codebases, obviously. You might get 50% of the
features above after tinkering for a few days/weeks/months with your vim with
(probably) much worse usability, when you could have used Visual C++ from the
get-go and enjoyed a "real programmer's editor", as you put it.

This bullshit religion you are introducing only hurts potential programmers
because instead of focusing on getting their job done they have to reinvent
the wheel every time they have to write a line of code. I'm not saying it's a
bad thing for a young mind to experience the horror of having to debug a
500.000 LOC codebase with a stone-age debugger, just for the kicks ("that's
how your old man was programming back in the day, son"), but when you have to
meet deadlines and release something going vim-only can quickly become a
liability.

~~~
Ygg2
Sadly in Linux you don't have the luxury of Visual Studio and I've tried doing
portable C/C++ in Windows (with cygwin and various make programs). It just
doesn't work right.

But I agree with overall sentiment. We shouldn't try to make programming hard.
It is hard already.

------
millerfung
Nevertheless, Zed is helping lots of people out there who is eager to learn
coding like me, I could imagine back in the days if you want to learn coding
there are tons of resources out there, probably too many, that you don't know
which one is good and it cost you money. Now, people like me can always go to
his book finish the course and look for what is missing without spending a
buck.

------
bendemott
I'm really glad to see that C can get in the spotlight even on HN.

~~~
rudiger
Is it really surprising that C can get in the spotlight even on Hacker News?
It's the quintessential hacker programming language!

~~~
bendemott
I guess I wasn't feeling an optimist on the day I posted that... Good Point!

------
Mithrandir
There's also a "Learn Python The Hard Way" course:
<http://www.udemy.com/learn-python-the-hard-way/>

------
arturhoo
There is a typo in the first sentence: "This will be the companion course to
my new book, "Learn C The Hard Way" whch I'm working on right now".

You probably want to fix that.

------
thdn
I'm really considering to take this one, but I've would like to consider other
alternatives, anyone knows other online c classes?

~~~
zedshaw
The video course is being worked on by me while I write the book, so expect it
to be rough around the edges.

But, I say try going through the HTML version online, and as you do get stuck
write comments to ask me questions. That's why I put it online for free, so
that I get student feedback while I write the book.

------
baby
It's funny how, I started getting annoyed seeing people still learning to code
on books while free tutorials were starting to pop up everywhere on internet.

And now people are starting to charge for those tutorials. And I know people
here in HN love Zed Shaw. But come on, there are hundreds of free great
tutorials to learn C on internet.

~~~
zedshaw
My HTML version is still free, and if you tell me of the free C books I'll
link to them here:

<http://programming-motherfucker.com/become.html>

~~~
baby
Right, started reading into it. Very good! Thanks.

------
z1g1
I am working with his learn python the hard way course on udemy and his book
and videos have helped me get going

------
ryansama
Most awesome. Even though it have plenty already, I would be more than happy
to pay more for more chapters.

------
jheriko
I did look at this book a while ago, I was unable to make amendments to the
code examples. early versions made common C gotcha mistakes, although of the
more subtle and less disasterous kinds... starting with non-standard entry-
point function signature and generally relying on non-standard features of
particular compilers. fortunately someone else seems to have gotten there in
the end... i'd be wary, simply because the author is (as much as I am a fan of
much of his work) clearly not an experienced C programmer.

~~~
zedshaw
I am a very experienced C programmer, and I have full comments on any page.
You find an error, drop a comment and I'll fix it immediately.

Chances are though, you're someone who read the K&R chapter, then went through
nitpicking minor semantics about things like "NULL is 0" and then consider all
the code broken in the book.

But, any errors you find, let me know and I'll fix them. Just don't call me an
inexperienced C programmer.

