Live data from Hacker News

Learn C The Hard Way

learncodethehardway.org

161–170 of 260 posts

Re: Learn C The Hard Way

#161
post #5

Do people really think C is some mysterious, inscrutable language? "To many programmers, this makes C scary and evil." Is this actually true for people? I find C code generally very easy and straightforward to understand; there's not any magic behind the scenes, like there is in any language that's more "high level" than C.

Many of the friends I made in my CS classes were terrible with pointers. I never really understood why they didn't grasp pointers, but it was a major stumbling block for them in C/C++

    I never really understood why they didn't grasp pointers
The root of the problem is the language designers' loose use of star. "star something" is contained in a phrase that means one thing at declaration, "star something" has a different meaning the rest of the time.

    #include 
    void eg(int i) {
        int *j = &i; // "huh? Put the address of i into *j?"
        *j = *j + 1;
        printf("%d\n", *j);
    }
    int main() {
        eg(4);
    }
With more detail. In the line..

    int *var = something;
.. the system assigns to the pointer. Yet in..

    *var = 6;
.. it assigns to the contents of the pointer.

Common usage creates further room for confusion:

    int *var; // 
If they'd made the syntax ".int var", and then used * solely for dereferencing, people wouldn't have these problems learning pointers. Consider

    #include 
    void eg(int i) {
        .int j = &i;
        *j = *j + 1;
        printf("%d\n", *j);
    }
    int main() {
        eg(4);
    }
Further confusion comes from (1) special arrangements around string declaration and (2) printf use of %s to expect a string pointer when %d and %f expects (non-pointer) simple int and simple float.

    char* something = "huh? so now this does goe into *something?";

Re: Learn C The Hard Way

#162
post #83

I learned C the hard way by taking this course, motherfucker http://www.cs.columbia.edu/~jae/cs3157/2009-1/syllabus.html http://www.cs.columbia.edu/~jae/papers/3157-paper-v2.2-camer...

Actually, that looks like a pretty easy way to learn C; a whole semester on it, beginning with things like using ssh? With instructors and TAs?

But ooh, Columbia, so you know it's hardkore.

Re: Learn C The Hard Way

#163

Earlier quoted context omitted.

I imagine terseness was a lot more valuable when everyone was programming on an 80x25 (or smaller) terminal or even punch cards. I've seen a few examples of code like this from early libc implementations of functions like strcpy, malloc, etc. Take a look at the source code of BSD libc -- some of that stuff is historic. I myself never got much into the terseness game, since apart from a brief stint using gwbasic and l…

This type of code used to run faster when compilers did less. It makes no difference now. I think that is why it has stuck around. I prefer to write C that uses array references where it makes things clearer.

You'd be surprised what the compiler still doesn't do. For example, when writing a toy high-performance memory allocator for a university class, I was able to gain a significant[1] performance boost by replacing __attribute__((packed)) structs with pointer arithmetic #defines for the allocation block descriptors, with an identical memory layout.

[1] I don't remember the exact gain, but it was at least 10%.

Re: Learn C The Hard Way

#164

Earlier quoted context omitted.

I'm glad you got so much about how my book is written from a few paragraphs in an unfinished manuscript for it.

You should stop thinking everyone is attacking you. I think you'd be happier. Really though, there's no content here. The fact it's been voted to #1 on hackernews shows just how bad things are. Items should be upvoted on their merit, rather than who did them. Someone writing another book about programming C isn't newsworthy.

I don't really understand your comment.

1. The post is about Zed's draft; is it really so far of a leap to interpret hp's remarks as a criticism of the book?

2. Is this a fair paraphrase? "Everyone here isn't attacking you, also, your draft sucks and shouldn't have been posted on HN."

Re: Learn C The Hard Way

#165

Earlier quoted context omitted.

When your second sentence is: "Play me a tiny violin ;-)" it isn't just idly chattering. It comes across as extremely petty and derogatory.

When somebody directs "derogatory" remarks at themselves , it's called "self-deprecating". It's a good thing in many Western cultures at least, and demonstrates a degree of modesty. In this case, hp made it clear that he doesn't expect sympathy (or applause or whatever) for having written a lot of C. It's just something he mentioned because he thought it was relevant. It is relevant - people not long out of school an…

"When somebody directs 'derogatory' remarks at themselves, it's called 'self-deprecating'... In this case, hp made it clear that he doesn't expect sympathy (or applause or whatever) for having written a lot of C. It's just something he mentioned because he thought it was relevant."

This isn't the only possible interpretation of that comment. Sometimes words can have more than one meaning, and misinterpretation isn't always a sign of idiocy or acting in bad faith

Also, when you say, "This contrasts with the negative, personal and poorly reasoned attacks of people such as you," do you mean, "I hope for your sake that ... you're only a few years out of school and haven't learnt to communicate yet, and not just an old hand trapped an inability to relate to people with different opinions or role models"?

Re: Learn C The Hard Way

#166

Earlier quoted context omitted.

I think the level of self-promotion and/or other-people-promoting-him is the key factor. Not really the supposed productivity. I know many people who get a lot done, both for day jobs, for contract work, as a hobby, as entreprenurial ventures, etc. but 99.9% never hits the front page of HN on a regular basis like Zed's activity seems to. Which doesn't lessen what he does and his skills, but it does pull back the came…

I personally have no idea why this stuff hits this site that often. Take this for instance: It is a half-finished manuscript that I announced in a tweet to people who follow me on twitter and asked for it. Already at the top of this set of comments is a dickhead saying he's such a bad ass 'cause he's changed "half a million lines of C code" and he thinks I'm not writing the book correctly because I'm being too low le…

Why is it that every comment I read by you is either you whining about being treated unfairly or you attacking someone who supposedly "attacked" you? Are you honestly that insecure? Do you read every comment as though it is in some way attempting to degrade your image?

Here you denigrate the HN community, saying it doesn't generate a significant amount of traffic for your site or whatever, and then go on to say you won't respond to the petty "idiots". I see. You're too "professional" for that. Obviously HN is so meaningless to you that you needn't bother with it. Yet you're here, commenting, making an ass out of yourself.

Woe is poor Zed Shaw; always the victim.

Re: Learn C The Hard Way

#168

Earlier quoted context omitted.

I'm glad you got so much about how my book is written from a few paragraphs in an unfinished manuscript for it.

You should stop thinking everyone is attacking you. I think you'd be happier. Really though, there's no content here. The fact it's been voted to #1 on hackernews shows just how bad things are. Items should be upvoted on their merit, rather than who did them. Someone writing another book about programming C isn't newsworthy.

Someone writing another book about programming C isn't newsworthy

However, "someone who wrote a ground-breaking introductory book in xyz modern-popular-hip language is turning his attention to C, of all things" is newsworthy.

Re: Learn C The Hard Way

#169

Earlier quoted context omitted.

I imagine terseness was a lot more valuable when everyone was programming on an 80x25 (or smaller) terminal or even punch cards. I've seen a few examples of code like this from early libc implementations of functions like strcpy, malloc, etc. Take a look at the source code of BSD libc -- some of that stuff is historic. I myself never got much into the terseness game, since apart from a brief stint using gwbasic and l…

The Go language tutorial and examples look right at home alongside K&R. Likewise jQuery and other Javascript libraries, where terseness is valued due to bandwidth rather than screen size. The idiomatic C style is so natural to me now I don't see it as a defect to fix or a game I'm playing. It's how I learned to program in C because I learned from K&R, and if they aren't the authorities I don't know who is. When I see…

"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." --Brian Kernighan Not to mention people aren't as smart as you debugging/understanding it. Also that code relies on the order of operations which I wouldn't recommend outside of math because it can be confusing. And it doesn't check that s isn't null.

Java is considered verbose for a number of reasons. It has a number of variable modifiers, it uses long names(which are generally good but can be stupid, especially in some cases of identifying multiple abstraction levels), and because it lacks type inference for generics and collection literals. c frequently makes the opposite mistakes with tiny cryptic or non whole word names. C lacks generic programming, it does do a decent job with initializers but unfortunately those can only be used at initialization.

Re: Learn C The Hard Way

#170
post #22
post #10

Earlier quoted context omitted.

Got any feedback on the things students get wrong? My experience is they fail to grasp memory management, pointers, functions as pointers, linkers or just how a program actually runs. If you've got others I'd love to hear them.

As a teaching assistant for a class ( http://www.cs.cmu.edu/~410/ ) where students write a whole lot of code in C, please introduce the address-of (&) operator and explain how to obtain pointers without using malloc(). Do this before the concept of the heap is ever introduced at all. Be careful when explaining the compiler and how a program actually runs. I've found that a lot of student problems come from "the compi…

can you get around the second without typeof(a gnu extension)?
Post reply on HN