Live data from Hacker News

C for high level programmers (slides)

charliethe.ninja

41–50 of 129 posts

Re: C for high level programmers (slides)

#41
post #24

Earlier quoted context omitted.

May I suggest that you also send them a link to Zed Shaw's "Learn C The Hard Way" online book [0], which presents lessons in modern C programming, including the use of tools like Valgrind, etc.? [0] http://c.learncodethehardway.org/book/

I just wrote a comment [0] about my problems with learning C, would you say this book covers the issues that I raised and is worth reading? EDIT: Well, I just looked over the chapters in this book and I'm now extremely excited to give it a read. It seems to cover most of the topics that I'm interested in, so thank you SO MUCH for sharing! [0] https://news.ycombinator.com/item?id=9636122

I think it might not cover them, going by this: http://hentenaar.com/dont-learn-c-the-wrong-way

Re: C for high level programmers (slides)

#42

As someone who just reread "C Programming Language", in chapter 1 they teach you how to count occurrences of characters so I'm not sure I understand the sarcastic tone of "you're not going to count foo in a file". C can be used for many things, I don't think the author of the slides dod a great job of describing "when" C is the right tool for the job.

I think he is just saying that C isn't worth learning if you just need to do really simply things that a ton of modern languages can do in one of two lines.

Re: C for high level programmers (slides)

#43

I think the problem with learning C is that you need to learn stuff like make, autoconf, how the compiler + preprocessors work (what do all those flags even mean!?), how making "cross-platform" stuff works, how to pull in and use "libraries", C-isms, how to test, etc. C itself is a very small and simple language, but the tooling and patterns are old and mysterious. In college I learned how to program embedded systems…

Personally, the hardest part for me was keeping track of the size of everything. Coming from a higher level language, keeping track of the bits and bytes takes some getting used to. Working with arrays in C is much tougher especially when the compiler will compile almost anything you give it, and even a small mistake is catastrophic. Before C, I was pampered and took everything for granted. Now I appreciated my life…

My pet hate is #include files. The whole way that C handles multiple source files just seems archaic to me, having worked in higher-level languages. I wish C had a proper package system that was standard, so I don't have to mess around with things like include file path order (or my favorite, the C++ template definitions having to be in the header files thing I only recently learned about).

Re: C for high level programmers (slides)

#45
post #15

Earlier quoted context omitted.

There was a mention of garbage being returned from an out of bounds array.

Unfortunately, UB extends far beyond that. To the point of being (very) logically inconsistent. People not familiar with C would naively expect that, for instance, `x[10] == x[10]` is always true even if 10 is out-of-bounds for x (or rather: it may crash, or it may be true.) . But compilers can - and will - assume that this situation is false if it makes the code faster. This sort of thing is my major pain point with…

Not only can the compiler make it false. It can assume that the code would never make the comparison in the first place, and optimize away any cases where the undefined behavior is guaranteed to be triggered.

So in a sense undefined behavior can travel back in time :O

Re: C for high level programmers (slides)

#46
Slide 31 says:

    Actually, this is how arrays are handled in C.
    A C array is a set of consecutive memory addresses.
    The first value is pointed to by a pointer.

    int a[] = {1, 2, 3}; // create an array
    // a is just a pointer to the first element...
No, "a" is an array, not a pointer. Defining an array object does not create a pointer. The expression "a" is implicitly converted to a pointer to the array's first element in most but not all contexts.

If "a" were nothing more than a pointer to the first element of the array, then "sizeof a" would yield the size of a pointer rather than the size of the array object.

This is all explained very well in section 6 of the comp.lang.c FAQ, http://www.c-faq.com/.

Re: C for high level programmers (slides)

#47

Earlier quoted context omitted.

Personally, the hardest part for me was keeping track of the size of everything. Coming from a higher level language, keeping track of the bits and bytes takes some getting used to. Working with arrays in C is much tougher especially when the compiler will compile almost anything you give it, and even a small mistake is catastrophic. Before C, I was pampered and took everything for granted. Now I appreciated my life…

My pet hate is #include files. The whole way that C handles multiple source files just seems archaic to me, having worked in higher-level languages. I wish C had a proper package system that was standard, so I don't have to mess around with things like include file path order (or my favorite, the C++ template definitions having to be in the header files thing I only recently learned about).

Interestingly, I first started with C (although I haven't written a line of C code for a long time), and when I first move to higher-level languages, I dislike the fact that I have no idea where the file I just imported is. Moreso when I'm playing with obscure/ new language: if I can just import whatever files I wanted (rather than at package level), it seems that would be much easier to hack on the language/std itself.

Re: C for high level programmers (slides)

#48

Earlier quoted context omitted.

The issue with undefined behavior is it's kind of hard to... well... define. It's an odd combination of unsafe memory, float/integer rollover, and rules with memory allocation. I wasn't quite sure how to clearly state it.

Yeah I tend not to get hung up on the different ways it can trigger. It's more like, if you trigger it your program might run fine for now and then suddenly act up one day. It might die before the undefined behavior. It might launch nukes. Still sure you want to get into this? No? Want to go back to Ruby? Well, Ruby is built atop C. That's the five states of grief I try to get them through.

Worse than that - undefined behaviour can cause optimization to make your software insecure.

http://blog.llvm.org/2011/05/what-every-c-programmer-should-...

Re: C for high level programmers (slides)

#49
post #46

Slide 31 says: Actually, this is how arrays are handled in C. A C array is a set of consecutive memory addresses. The first value is pointed to by a pointer. int a[] = {1, 2, 3}; // create an array // a is just a pointer to the first element... No, "a" is an array, not a pointer. Defining an array object does not create a pointer. The expression "a" is implicitly converted to a pointer to the array's first element in…

It's also worth pointing out that there are no array parameters. If you write

    void foo (char bar [42]) {
        // ...
    }
then within the scope of foo, bar will be a pointer to char, not an array of char. You can, on the other hand, write

    void foo (char (*bar) [42]) {
        // ...
    }
in which case bar will be a pointer to array of 42 char (and notably, not a pointer to a pointer to char!).

C does some very strange things. There usually is (or at least was) a good reason for it to do so, but especially if you're a beginner, you need to be on your toes if you really want to use it well.

Re: C for high level programmers (slides)

#50
post #33

I think the problem with learning C is that you need to learn stuff like make, autoconf, how the compiler + preprocessors work (what do all those flags even mean!?), how making "cross-platform" stuff works, how to pull in and use "libraries", C-isms, how to test, etc. C itself is a very small and simple language, but the tooling and patterns are old and mysterious. In college I learned how to program embedded systems…

Javascript has the same problem, but I think its worse. At least there are platform standards in C (autotools in GNU, msbuild on Win). Trying to figure out how Grunt/Gulp/Broccoli, LESS/SASS/Stylus/Jade, Coffeescript, Uglify, Bower, Browserify, Require.js, AMD/CommonJS, NPM etc all work together is a nightmare. It's all too hard, so people added Yeoman, Brunch, or other things to generate application configs - but no…

Yep. I'm more comfortable with Make than I am with JSPM/NPM and System.js. The process to minify my javascript and CSS and then replace the paths in the HTML so my pages actually work seems to be needlessly complex.

I'm seriously considering whether I can use Make for my production website builds - the only issue is Windows support.

Post reply on HN