
Don't Learn C the Wrong Way - voltagex_
http://hentenaar.com/dont-learn-c-the-wrong-way
======
hoodoof
>>Let me start by saying that unlike Mr. Shaw, I am not a writer. I'm an
engineer.

Zed Shaw, whilst his approach to certain issues may be questionable, is _not_
"a writer rather than an engineer".

Zed is known as one of the most prolific and capable software engineers around
and I have heard his C code for Mongrel 2 server
[https://github.com/zedshaw/mongrel2](https://github.com/zedshaw/mongrel2)
described as being amongst some of the best examples of C code to study, learn
and understand (trying to find the link that said that). I hold his work in
high regard.

I don't agree with everything that Zed does and think it's a pity that his
combative and dogmatic nature detracts from the core message about his work,
but the author of this blog post is off track if he is trying to suggest that
Zed doesn't know what he is doing and is "a writer" rather than "a software
engineer". Zed is a (cantankerous) _software engineer and a writer_.

The attempt to discredit Zed's credentials just discredits the blog post and
its author. When criticizing, criticize the work rather than the person.

~~~
knowtheory
At this point people just keep trying to pick fights with Zed. He's not out
there picking fights with others (well any more than anyone else).

And all of the posts pointing this out all disclaim that "while they don't
agree with Zed about some things..."

It's just kind of sad from a rhetorical perspective.

It's clear that the guy who wrote this post doesn't agree with Zed's
pedagogical style, but that doesn't make Zed's book wrong in detail or
approach. It just means this guy doesn't agree with the style. And he's not
upfront about it either due to a lack of introspection or forthrightness.

~~~
ealloc
It sounds like more than a just a "style" disagreement.

In the discussion of C strings, the author is arguing that Zed's arguments are
nonsensical, maybe even objectively wrong. I write a lot of C, and the author
is right in this case about C strings and undefined operations. In C you must
arrange your code so that you always supply valid input to functions, there is
no way around it, and it is perfectly safe once you do so.

I'd rather see discussion of the actual arguments, rather than complaints
about the article's tone. :)

~~~
knowtheory
Zed's book is concretely about introducing programmers (particularly new ones
or ones going from higher level managed languages down into C) to where and
how C can be dangerous especially around string management.

And that's why this _is_ a style issue. Even if he disagrees with Zed's
approach (and in particular how undefined behavior is discussed) it's just
mendacious to claim that Zed isn't introducing his readers to the idea that
one needs to be careful with strings and understand what kind of inputs one
will receive.

This is a critically different behavior when compared to Ruby or Python where
string management is done for you, and coming from the POV of someone who's
familiar with those languages... Zed's approach makes sense. Especially when
the alternative being suggested is "you absolutely must go read the C spec and
K&RC".

------
_kst_
Part 3:

"Wait a tic... Where's the Makefile? I've got just about as much chance of
finding it as the FBI does of finding Jimmy Hoffa. Am I just supposed to
imagine it into existence?"

I think the point is that the make command can use implicit rules even if
there is no Makefile. It knows how to compile C source files. (This could be
confusing if you know about "make" but don't know about implicit rules.) For
example:

    
    
        $ ls
        hello.c
        $ cat hello.c
        #include <stdio.h>
        int main(void) {
            puts("hello");
            return 0;
        }
        $ make hello
        cc     hello.c   -o hello
        $ ./hello
        hello
        $
    

Later: "So, I'm just supposed to poke in some code, go to my terminal, type
this magic 'make' word, and expect a built and working program, right?"

Yes, that's exactly what you're supposed to do. Try it, it should work.

Part 10 mentions strncpy() as a safer strcpy(). It isn't. [http://the-flat-
trantor-society.blogspot.com/2012/03/no-strn...](http://the-flat-trantor-
society.blogspot.com/2012/03/no-strncpy-is-not-safer-strcpy.html)

(Disclaimer: I haven't read Zed Shaw's book, and I don't intend to.)

~~~
albinofrenchy
I'm glad you posted the article on strcpy; I did not know about this behavior
of strncpy and am a little surprised I never ran into it before.

That being said; it is a safer alternative to strcpy, but it seems like it
isn't the _safest_ alternative to strcpy.

~~~
xerophyte12932
What about strcpy_s ??

~~~
_kst_
strcpy_s is not universally available.

------
jauer
The entire article reads as a thinly veiled diss on Zed by someone that
(badly) skimmed LCTHW.

Things like:

1\. Griping about format strings not being explained until it's necessary to
understand them even though it's suggested that you look into them right away
in the extra credit section.

2\. Griping about non-existent Makefiles even though they are explained in
multiple sections, one where he chose to spend time dissing on the section
title instead of actually reading it and seeing that you write a makefile.

It feels like the author believes that there's a "one true way" to teach a
language and that Zed's way isn't it.

I for one am grateful for alternatives to textbook-style books, be it Learn X
the Hard Way or the O'Reilly Head First books.

------
jasonlotito
> C was designed on UNIX, and was basically made for UNIX. That's a matter of
> historical record. But to say that on Windows everything is a little "off",
> doesn't quite do it justice. I understand that the book is aimed at the
> uninitiated, but to put it that mildly is an understatement of epic
> proportions.

Yeah, this was the fist sign I wouldn't read to the end, and I was right. The
author just says this, and leaves it at that. As if we are to just take his
word for it. This is essentially what this argument boils down to:

"He said X, I say X++." No explanation, nothing to backup what he says,
nothing other than a to suggest it's a epic understatement.

Let's put this another way: my comment is has more to backup what I say than
this article. The author might be right, but he doesn't back it up.

~~~
ufo
And I don't even understand why he doesn't agree that C is a second-class
citizen on Windows. Microsoft would rather have you code stuff in C++ or .Net
and MSVC is stuck with the C90 standard (although apparently that is finally
improving)

~~~
e12e
On the bright side, the author's hate for implicit make-rules, and inability
to grasp the pedagogic value of showing implicit includes first, and -Wall
later made me go and test the following in a "command prompt for VS2013" on
windows:

    
    
      >more hello.c
      int main(int argc, char *argv[])
      {
        puts("Hello world.");
        return 0;
      }
    
      >cl hello.c
      Microsoft (R) C/C++ Optimizing Compiler Version 
      18.00.31101 for x86
      Copyright (C) Microsoft Corporation.  All rights reserved.
    
      hello.c
    
      Microsoft (R) Incremental Linker Version 12.00.31101.0
      Copyright (C) Microsoft Corporation.  All rights reserved.
    
      /out:hello.exe
      hello.obj
    
      >hello
      Hello world.
    

Things are getting better.

~~~
bzz01
>Things are getting better.

In what sense? MS platform had a working C compiler for decades.

~~~
e12e
Working, and "easy to use" isn't the same thing. For one thing, this is a
gratis compiler from MS.

~~~
shadowfox
Not quite sure what is new here. The MSVC compiler has been available for free
for close to a decade at least and command line compilation was available ever
since I first used it (in the mid 90s)

~~~
e12e
I wasn't aware of that. I suppose it came with the driver dev kits? I've not
really been into windows development, but I thought I'd at least have brushed
up it accidentally if one could use the official MSVC compiler to produce
shareware and commercial software for free?

Were there any (free) IDEs that took advantage of this? I thought one of the
reasons Stevens used DJGPP was that MSVC wasn't available for free? I suppose
I could just be that it wasn't freely distributable, which makes it hard to
bundle with a book (at a time when people can't just go and download megabytes
of data from microsoft.com).

Or maybe MSVC was free, but not the c++ part? See eg:

[http://www.atarimagazines.com/compute/issue162/52_Windows_pr...](http://www.atarimagazines.com/compute/issue162/52_Windows_programming.php)

(It's not my intention to move the goalposts, you say close to a decade, which
means 2005 -- it's quite likely that I'm just biased due to my old age...)

I did find this:
[http://blogs.msdn.com/b/vcblog/archive/2006/06/08/622485.asp...](http://blogs.msdn.com/b/vcblog/archive/2006/06/08/622485.aspx)

Which reminded me of VS express -- which isn't the same as a full version (but
should/did work for "hello, world!"). See also eg:
[http://www.i-programmer.info/news/89-net/7976-full-visual-
st...](http://www.i-programmer.info/news/89-net/7976-full-visual-studio-now-
free.html)

How did you get a free c-compiler from MS in the mid 90s?

~~~
shadowfox
I did literally mean a decade for the compiler (so 2005). While it is not a
full IDE by any means, VS Express did include the standard VS compiler. You
could compile most standard C programs on windows with that. For some time
prior to that you could get a compiler with the DDK as well (but I don't
remember since when; it has been a long time). Of course express didn't pack
some of the libraries that came with VS; you could get most of them via the
SDK and DDK however.

In the 90s though, I used the non-free VS for the most part along with some
Cygwin until Mingw's appearence in the late 90s.

------
ufo
To me this read like a long list of nitpicks. Sounded like the author was just
angry that Zed said bad things about the K&R book.

~~~
velodrome
Yup. He does not offer alternatives to Zed's work either.

~~~
voltagex_
I'm looking for an alternative. I found this article in
[https://news.ycombinator.com/item?id=9635230](https://news.ycombinator.com/item?id=9635230)

------
velodrome
_Learn C The Hard Way_ is more like opinionated tutorials not a textbook. It's
great for someone just getting started. If I were to hand someone K&R - The C
Programming Language, their interest would instantly vanish. Why not start
with something small (like The Hard Way) and work your way up from there.

To get good at anything, you have to constantly read and apply your knowledge.
Why should this be any different?

------
barbs
I wonder if this was the last straw the spurred his latest blog post?

[http://zedshaw.com/2015/06/01/dear-paul/](http://zedshaw.com/2015/06/01/dear-
paul/)

------
mayukh
Here's my 2 cents. Learn any language any way you want and don't give a shit
for pretentious blowhards who tell you otherwise. Peace and love !
[https://www.youtube.com/watch?v=hIJdFxYlEKE](https://www.youtube.com/watch?v=hIJdFxYlEKE)

------
brudgers
Transcript of Scott Hanselman's interview with Zed Shaw:

[http://s3.amazonaws.com/hanselminutes/hanselminutes_0407.pdf](http://s3.amazonaws.com/hanselminutes/hanselminutes_0407.pdf)

------
bharani_m
I just read the entire article and I can't find one decent comment about why
Zed's teaching methodology is wrong or why he shouldn't be writing a book on
C.

All I see is the author fussing about coding style and some such.

------
M_alice
Ok, now this piece of crap of an article is exactly WHY I am going to learn C
the hard way. Obviously, not the only reason, but certainly one of them.

------
a-saleh
I'd like to hijack part of this discussion and ask, if any of you know about a
good modern c programming book.

Because I'd like to read the K&R C destructuring book, not just a removed
chapter at the end of the book :-)

I somehow thought that notion, that K&R C is somewhat outdated in their code
examples is widely accepted (biggest gripe is little to no input sanitation,
afaik (?)), so a book about "this is what we learned about c in past 30 years"
would be splendid :-)

~~~
anth1y
[http://shop.oreilly.com/product/0636920033677.do](http://shop.oreilly.com/product/0636920033677.do)

Hope this helps....

------
toothrot
Somehow the critique lost clout at "Winblows"

