7 ms·
Don't Learn C the Wrong Way
- hoodoof 11y ago>>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.
- wyclif 11y agoThis is the second time this post has been voted to the front page of HN. It's puzzling. Are C programmers supposed to find this compelling now, when they didn't the first time around? I wonder if it's simply a case of: 1. Zed Shaw is controversial on HN 2. I know, I'll write a post that disses Zed Shaw 3. ??? 4. Profit!
- voltagex_ 11y agoSorry, I didn't find it the first time around. I think it's generating good discussion. I didn't post it to diss anyone. The article seemed a little off to me, and I thought HN would enjoy picking it apart
- knowtheory 11y agoAt 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.
- hoodoof 11y agoPeople who behave in a combative and dogmatic manner have not programmed in to themselves a check to ask "does this issue really matter?". There is no decision making code in their brain to work out if something REALLY matters. Many things, even small things, matter enough to go to war. They also value the war/being right/the point more highly than they value maintenance of positive human relationship. What they don't understand is that people forget the issue and remember the grace (or not) with which you handled it. Often they are not very good at empathizing with others and find it hard to imagine what it is like to be someone else interacting with them. I know cause I am one, hopefully reformed.
- reality_czech 11y agoI agree that the tone of the blog post could have been less combative, but essentially all of this complaints are valid. Zed's does introduce things in the wrong order and in a very confusing fashion. The rant about C strings is also completely misguided and would lead a novice off course into using ugly thickets of macros and crappy frameworks rather than simply using C strings correctly. Any C function will misbehave if passed invalid input... and things like valgrind, which Zed is clearly well aware of, make C-style strings much less dangerous. Zed also made many completely unjustified attacks on the K & R book, which is a well-written, easy to read book which introducse C concepts in a clear and readable way. Even if this was justified (and it's really, really not), that all belonged as a separate blog article rather than as part of an alleged "tutorial." Finally Zed published a "rebuttal" to all of this in which he basically says that C sucks, is not worth learning, and he's learning Go. So the author quite reasonably asks, why would you want to learn C from someone who doesn't like the language or think it's worth learning? I think we can all agree that Go (or some other high level language) probably is the better choice for most projects. But after all, there are still many places where C will continue to be used like the Linux kernel. Those people would be much better off reading K&R, as old as it is, than anything Zed has written. And his attacks on the K&R authors are just sad.
- ealloc 11y agoIt 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. :)
- caf 11y agoI don't believe your paraphrase of the line you quoted from the author is accurate. His own words, strictly read, imply that: - Shaw is a writer; - The author is not a writer; - The author is an engineer. It doesn't imply anything either way about Shaw being an engineer.
- knowtheory 11y agoThe full quote is "Let me start by saying that unlike Mr. Shaw, I am not a writer. I'm an engineer. Thus, this will be written from that perspective." By implication, Zed's book is not written from the POV of an engineer (otherwise why would this be worth noting in any way shape or form? The topic under discussion is already software engineering).
- hueving 11y ago>Zed Shaw, whilst his approach to certain issues may be questionable, is not "a writer rather than an engineer". He didn't say Zed wasn't an engineer. He just said that he isn't a writer so the article will be written in an engineering voice. People do the same things with presentations. "Sorry, I'm not a public speaker, so this might suck."
- necrodawg 11y agoI think it's a pity that people can't see past him being "combative and dogmatic". I don't agree that it takes away from the core message of his work at all. A lot of really smart people are cantankerous, and often they can afford to be.
- youngtaff 11y agoThe only time I've met Zed I found him to be a perfectly pleasant and non-cantankerous person. My understanding of his approach to teaching is that it's based getting people to do things that bring results and then getting them to understand why after - which I think is a perfectly sensible one for beginners
- bphogan 11y agoIt is very good. There's an educational philosophy around this that state that people who are new need to know "why should I care" first, then "how do I do it" next, followed by "ok, why does it work that way?" last. When you're cooking, you follow a recipe. When you are learning to be a cook, you graduate to figuring out why you do it the way the recipe did. And when you get really good, you start saying things like "Well, I wouldn't teach people to cook THAT way! That's wrong!" :)
- _kst_ 11y agoPart 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-strncpy-is-not-safer-strcpy.html http://the-flat-trantor-society.blogspot.com/2012/03/no-strn... (Disclaimer: I haven't read Zed Shaw's book, and I don't intend to.)
- albinofrenchy 11y agoI'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 11y agoWhat about strcpy_s ??
- _kst_ 11y agostrcpy_s is not universally available.
- _kst_ 11y agostrncpy, when used as designed, can leave the target array without a terminating null character. Using that array later with any string function causes undefined behavior. strcpy, when used as designed, always leaves the target array properly null-terminated. Using it properly is a bit more difficult; you have to make sure the target array is big enough to hold the source string. This sequence: target[0] = '\0'; strncat(target, source, sizeof target); does what most people probably assume strncpy should do (assuming target is defined as an array rather than as a pointer).
- mayukh 11y agoHere'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
- jasonlotito 11y ago> 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 11y agoAnd 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)
- hoodoof 11y agoWhen Windows first came out, the ONLY programming language for it was C. Nothing else.
- e12e 11y agoArguably, the only programming environment that's been bundled with windows is qbasic...?
- enry_straker 11y agoAssembly was always an option, though a painful one.
- e12e 11y agoOn 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.
- ufo 11y agoTo 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.
- chucksmash 11y agoThe author's jumping off point seems very much to be "I dislike Zed Shaw" versus, say, an earnest attempt to prevent novices from learning C the wrong way. That's a shame, because I think that would make for an interesting article.
- velodrome 11y agoYup. He does not offer alternatives to Zed's work either.
- voltagex_ 11y agoI'm looking for an alternative. I found this article in https://news.ycombinator.com/item?id=9635230 https://news.ycombinator.com/item?id=9635230
- rhizome 11y ago...but he does it with so much personality!
- velodrome 11y agoLearn 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?
- deleted 11y ago[deleted]
- jauer 11y agoThe 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.
- brudgers 11y agoTranscript of Scott Hanselman's interview with Zed Shaw: http://s3.amazonaws.com/hanselminutes/hanselminutes_0407.pdf http://s3.amazonaws.com/hanselminutes/hanselminutes_0407.pdf
- toothrot 11y agoSomehow the critique lost clout at "Winblows"
- deleted 11y ago[deleted]
- M_alice 11y agoOk, 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 11y agoI'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 11y agohttp://shop.oreilly.com/product/0636920033677.do http://shop.oreilly.com/product/0636920033677.do Hope this helps....
- barbs 11y agoI 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/
- bharani_m 11y agoI 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.