5 ms·
It's pretty important to note this is about how to teach C, not why. Should schools be teaching C at all? I would say yes, not as an introductory language but a
by notacoward 8y ago
It's pretty important to note this is about how to teach C, not why. Should schools be teaching C at all? I would say yes, not as an introductory language but as a precursor to studying kernels or databases or compilers. Real-life examples of these are mostly written in C, and studying such systems is IMO a necessary part of a CS curriculum. Therefore, at some point students need to learn C. They should certainly have the option, so we still need to address the question of how it should be taught.
With regard to that question, the OP seems pretty spot one. The identification of certain codebases as good or bad matches my own experience with most of them. The advice to use static analysis and to avoid preprocessor abuse is sound. There are only a few things I'd add.
* You can't really learn C without also learning to use a debugger - probably gdb. That must be part of the lesson plan.
* A more in-depth discussion of good error-handling and memory-management practices would be worthwhile, since C itself doesn't provide these.
* It can be very informative to implement some of the features found in other languages in C. Examples might include a simple form of object orientation, or a map/dict/hash, or a regex parser. Besides their value as a form of practice, this would expose students to some of the issues and decisions involved in making these a built-in part of a higher level language.
- eternalban 8y ago> You can't really learn C without also learning to use a debugger News to me. I learned C in '85 from the K&R book and the project lead for our little startup's Fortran to C translator. No debuggers were involved as far as I can remember. [p.s. as to "why" teach C. I know many languages at this point, but that initial exposure to C necessitated a deeper understanding of 'the machine', memory management, etc. The core of C is fairly straight forward and imho an excellent pedagogical vehicle for a 'substantial' understanding of "programming".]
- canhascodez 8y agoThe machine being used is completely incidental to programming. Dijkstra used a fountain pen. Which is more fundamental, the machine, or its mathematical abstraction? Why should people learn C, and not Lisp?
- eternalban 8y agoI wonder if Dijkstra used paper clips or rubber bands for "linking". (CS =/= Programming)
- canhascodez 8y agoPerhaps you could do me the favor of answering my question.
- eternalban 8y agoWhy should I bother with a red herring? We were discussing programming and not computer science.
- canhascodez 8y agoWhy teach C and not Lisp?
- notacoward 8y agoOK, I'll amend my statement. You'll waste a lot of time if you try to learn from or work on any substantial C codebase without knowing how to use a debugger. Some people have a lot of time to waste, but that doesn't make it a good idea.
- hackermailman 8y agoThe CS:App book introduces gdp, valgrind and the how the compiler works so linker/optimizations, how C looks like in assembly, and pitfalls so introduces the SEI CERT C Coding Standard http://csapp.cs.cmu.edu/ http://csapp.cs.cmu.edu/ and also tells the reader to go over K&R to look at how declarations differ. It's usually used for a introductory systems programming course covering enough you can poke through a systems library and know what's going on but to actually teach C development would be a much different course I would imagine.
- fiedzia 8y ago> precursor to studying kernels or databases or compilers While widely used kernels are still written in C, new ones are often not, and vast majority of new databases isn't either. Its java (Hadoop, Solr), Go (InfluxDB), Rust (Tikv) among others. That's if you want to be prepared for today. If you look into few years ahead, its also TLA+, Idris or Coq. Same for compilers, its increasingly rare to see anyone choosing C for that domain, especially as a language for teaching them. > Should schools be teaching C at all? I'd change this question to "should schools have any say in deciding what to teach?". Wouldn't be better to offer a list of options and let students do the market research and decide on their own? > It can be very informative to implement some of the features found in other languages in C That's not how programming works today. You are given those as language primitives and don't think about it same way you don't think how the hardware implements "if" in C. You may be curious and find some use for this knowledge if you have it, but its not very useful when you want to "teach C" (and its also very ephemeral).
- notacoward 8y agoI'm pretty sure the Linux kernel, BSD kernels, MySQL, Postgres, gcc, etc. will all be with us for quite a while. A few years ahead things won't be written in TLA+ or Coq because they're not even programming languages. Lamport is very explicit that TLAx is a specification language, and the central component of Coq (Galina) is too, so the name-dropping doesn't really make your case more convincing. C should definitely not be the only or even primary language people learn, but it's pretty critical to understanding how things work today and will continue to work for at least the next decade. > Wouldn't be better to offer a list of options I do believe I already said something like that. Yep, just checked. I did. The point is that, even if it's only an option, the question of how to teach it is still important. > That's not how programming works today. In your opposite-of-humble opinion, which is wrong. In fact, implementing things that are already pretty well known is exactly how programming is taught. Everywhere. In all languages. Students learn about pitfalls, and tradeoffs, and why "this" is easy/common but "that" is hard/rare. If you want to teach C, you have to teach C as it is used and why. A language is far more than just syntax you can learn from a book. Any student who has actually implemented a "basic language feature" in C is better equipped to understand how that implementation of that feature in a particular other language represents only one set of decisions within that space, and that others are possible. I'd say that's pretty important knowledge. Programmers who just settle for "it's magic" and "that's how it is" are never going to be very good programmers.