Live data from Hacker News

Don't Learn C the Wrong Way

hentenaar.com

41–50 of 53 posts

Re: Don't Learn C the Wrong Way

#41
post #33

Earlier quoted context omitted.

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

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)

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...

(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...

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...

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

Re: Don't Learn C the Wrong Way

#42
post #2

>>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 described as being amongst some of the best examples of C cod…

>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."

Re: Don't Learn C the Wrong Way

#43
post #2

>>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 described as being amongst some of the best examples of C cod…

I 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.

Re: Don't Learn C the Wrong Way

#44
post #3

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:…

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.

What about strcpy_s ??

Re: Don't Learn C the Wrong Way

#45
post #32

Earlier quoted context omitted.

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 Ze…

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 yo…

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".

Re: Don't Learn C the Wrong Way

#46
post #3

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:…

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.

strncpy, 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).

Re: Don't Learn C the Wrong Way

#47

Earlier quoted context omitted.

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.

What about strcpy_s ??

strcpy_s is not universally available.

Re: Don't Learn C the Wrong Way

#48
post #2

>>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 described as being amongst some of the best examples of C cod…

I 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.

The 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

Re: Don't Learn C the Wrong Way

#49
post #14
post #8

Earlier quoted context omitted.

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)

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) Micros…

> the author's hate for implicit make-rules

My reading was that the author just didn't know about implicit make rules. Shaw's book apparently suggests using "make" to compile and link a simple C program. The author goes on at some length about not being able to find the Makefile, apparently unaware that no Makefile is necessary.

The "make" command is rarely used without a Makefile, so this is a fairly easy mistake to make.

Re: Don't Learn C the Wrong Way

#50
post #41

Earlier quoted context omitted.

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)

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…

I don't think it was free, but again entire Microsoft toolchain wasn't free in 90s, so nothing special about C here.
Post reply on HN