9 ms·
Essential C
- nuttendorfer 14y agoThis looks like the perfect material to learn C if you already know how to program (or at least in C-like languages like Java and C#).
- viraj_shah 14y agoOh, this is fantastic. Thank you!
- kawaguchi 14y agoI've been trying to get through K&R for the past week or so. I think this will make things a lot easier. Thanks a lot!
- e12e 14y agoWell, that kind of invalidates part of the comment I was going to write: "How is this any better than K&R's 'the C programming language'?". I guess it all depends on background and personal preference. I've never become comfortable with C's pointer/reference/dereference syntax -- I much prefer Pascal in this sense. I recently had a look at Ada and was pleasantly surprised -- it has a very straightforward syntax. As other's mention here, I think C should be learnt with assembler (and computer architecture - especially the bit about cache hits/misses). I find that: http://www.drpaulcarter.com/pcasm/ is a great introduction to assembler and C -- and how the two (can) interact. Another thing I find frustrating with C is that it's still a bit of a pain to work with unicode/wide strings -- on my todo list is writing a short post on "Hellø wørld (with unicode)" -- with some examples of wide strings in C, (possibly Pascal) and ADA -- along with assembler output and a "pure" assembler version. There is surprisingly little good material on the web for this (that I managed to find, anyway).
- crag 14y agoI also thought C should be the first language anyone learns. Cause you learn the most (about the machine) and other languages are easy peasy compared (well except for assembler, of course).
- derleth 14y ago> Cause you learn the most (about the machine) Except when it comes to cache, pipelining, registers, non-uniform memory access in general (not just cache), out-of-order execution and opcode pairing rules, SIMD architectures, and the existence of the processor status word. Other than that, yeah, C exposes you to a lot of worrying about memory allocation when algorithm design would be a better use of your time. > other languages are easy peasy compared The only way you could possibly say this is if the only languages you know are imperative Algol-derived ones with minimal type systems and no support for logic or declarative programming. Learning C doesn't make Prolog meaningfully easier. Learning C doesn't even make learning a mainstream language like SQL easier.
- dsirijus 14y agoThis still doesn't successfully counter the statement that C is the best language to start with. I'm biased since C is my first language. Do you recommend another better suited for the purpose?
- dag11 14y agoMy first language was Javascript/Actionscript and then later Java. It wasn't until after that that I learned C and C++. But I agree that C should be one of the first languages learned.
- Someone 14y agoI would recommend almost anything with an interactive shell over a traditional C environment. Python and irb are nice starting points because you can start out by claiming they are just a calculator, where you have to press return instead of =. From there, you can go to variables (prevent you from having to type, e.g. the gravitational constant or a VAT percentage over and over), then to looping (print multiplication tables), to arrays (store them for later use, or as input for a loop to print year lengths for the planets, computed from their distance to the sun), and then to functions. And all of that without having to teach people the difference between source, object code, and executable.
- etanol 14y agoThe document talks about C89, even though the last Copyright year is 2003. Isn't it about time that we start movin on? Where are the restricted pointers, the flexible array member and so on? And, by the way, I think the comment at the bottom of page 27 is not correct: The qualifier const can be added to the left of a variable or parameter type to declare that the code using the variable will not change the variable. As a practical matter, use of const is very sporadic in the C programming community. It does have one very handy use, which is to clarify the role of a parameter in a function prototype... Actually, the use of const is encouraged as it helps the compiler to catch more errors as well as to enable some optimizations.
- zcvosdfdgj 14y agoC programmer for 15 years here... I'm sure some of the new stuff is nice, but the article is titled "Essential C".. and the basics of C are all old, because surprise: C is an old language. And the quote from page 27 is absolutely correct. Of course, you're also correct.. it is encouraged.. but other than function prototypes, it's rarely used. Even in function prototypes, it's left out most of the time.
- stephencanon 14y agoThis; a few other especially inexcusable oversights that result from ignoring C99: - telling students to make up types like Int32 or Int16 instead of using the fixed-width types defined in <stdint.h>. - Claiming that // comments are "not technically part of the language". - "C does not have a distinct boolean type."
- pmjordan 14y agoThere's another error here: The qualifier const can be added to the left of a variable or parameter type If you have the declaration char* str; Adding const to the left of the type doesn't make the variable immutable: const char* str; This indicates that str will point to a character or string which must not be mutated. str itself can be reassigned. To make str immutable, you need char* const str; // immutable pointer to mutable string or const char* const str; // immutable pointer to immutable string Const does tend to be used little in pure C, though you pretty much can't escape it in C++ code. (I also use it a lot in C, and have type warnings/errors cranked up to max)
- jorangreef 14y agoTrying to write JavaScript that takes advantage of a single engine such as V8, hidden classes, type immutability, performance of 31 vs 32 bits, lack of 64 bit integer operations, cost of closures, etc. in the end, you spend so much time trying to work within this indirection that C begins to look far less wasteful and more direct, in terms of both human and machine time, especially if you have the general design of what you're trying to do figured out.
- derleth 14y agoThis gets at one of the reasons I like Common Lisp: Common Lisp allows you to program at a high level and then stepwise refine your program to make it more efficient, such as by adding type declarations, adding other declarations, changing your data types, and, at an extreme, changing your algorithms to run without CONSing (that is, eliminating dynamic allocation and garbage collection), not to mention whatever your specific implementation provides as an extension to the standard. Most code can stay fairly high-level, but the tools are there and a standard part of the language if you need them.
- agumonkey 14y agoI've seen some lispers going 'full stack' programming. Clojurians (like this guy http://www.learningclojure.com/2010/09/clojure-is-fast.html http://www.learningclojure.com/2010/09/clojure-is-fast.html) also aim to cpu cycles when they program. It's an interesting workflow to prototype high and fast and the project it down baremetal.
- _delirium 14y agoThe fact that Lisp systems have traditionally included an easy-to-use asm inspector right in the environment is an interesting aspect imo. It's actually more common in my experience for Lispers to look at their generated asm than it is for (non-embedded) C coders to do so, because it's so easy to just (disassemble #'foo).
- 14y ago
- 3amOpsGuy 14y agoC is an excellent first language when teaching in a CompSci type environment. If the students are of a different discipline (not aiming to be CompSci grads) or much younger then i think there are better choices e.g. Python. In a CompSci academic setting i think learning assembly first (that is first programming language but in parallel with the other classes such as computer architecture etc.) is also a valid approach. Programming from the Ground Up [1] is a very accessible introduction to x86 ASM and even supposing you don't go any further than the examples in this book, you'll still feel the benefits. [1] http://ftp.igh.cnrs.fr/pub/nongnu/pgubook/ProgrammingGroundUp-1-0-booksize.pdf http://ftp.igh.cnrs.fr/pub/nongnu/pgubook/ProgrammingGroundU...
- jorangreef 14y agoThanks for the link, found a choice quote from there on page 234: "If you are constantly looking for new and better ways of doing and thinking, you will make a successful programmer. If you do not seek to enhance yourself, 'A little sleep, a little slumber, a little folding of the hands to rest - and poverty will come on you like a bandit and scarcity like an armed man.' Proverbs 24:33-34"
- tripzilch 14y ago"And thou shalt make loops" Exodus 26:4
- jlgreco 14y agoI am split on if I think C/assembler is the best introduction material for computer science, or if scheme is. What I am rather certain of though is that just about everything in-between is not. You don't really see the best of both worlds, but rather the worse. (I should probably clarify that I think there is a large disconnect between what makes a good language for teaching and what makes a good language for software development in a corporate environment.)
- cpeterso 14y agoI think the best introduction would be Scheme (to learn algorithms), assembly language (to learn machines), and then C (to unite the two). After that, I would recommend some strongly-typed language like Haskell or OCaml. And finally Python to actually get work done. :) My friend said that UC Berkeley's undergraduate CS program followed this introduction. (In the 1990s, at least; I don't know about now.)
- sharms 14y agoI really enjoy the short / succinct format of this, does anyone have links to similar documents for java / javascript / C++?
- jetsnoc 14y agoNick Parlante is an exceptional instructor. I highly recommend Google's Python Class he instructed.
- tiffani 14y agoI highly recommend this and a bunch of other C-related stuff in the Stanford CS library. Their pointer explanations helped me many, many years ago. http://cslibrary.stanford.edu/ http://cslibrary.stanford.edu/
- manaskarekar 14y agoAlong with Kernighan and Ritchie, I would also highly recommend getting a copy of 'C: A reference manual' by Harbison and Steele. That book explains a lot of stuff by topic and with descriptive examples. Especially beneficial for a quick reference. Highly recommended.