4 ms·
> The syntax uptake is pretty quick, and would allow students to focus on the problem at hand (e.g. algorithms) rather than language nuance. I don't agree. Wha
by pcwalton 10y ago
> The syntax uptake is pretty quick, and would allow students to focus on the problem at hand (e.g. algorithms) rather than language nuance.
I don't agree. What's the benefit in having to painstakingly write trivial string operations using string.h and manually allocated buffers? What's the benefit in learning the ins and outs of undefined behavior?
- guyzero 10y ago"What's the benefit in learning the ins and outs of undefined behavior?" To force people to learn that making assumptions based on undefined behaviour is dangerous and that computers are not mind-readers. And you force people to write buffer manipulation code so they realize how good people using other languages have it.
- pcwalton 10y ago> To force people to learn that making assumptions based on undefined behaviour is dangerous and that computers are not mind-readers. You can do that in a lot less time with, say, Array.sort in JavaScript. Explaining that signed overflow is undefined, and why it's undefined, is a whole lot of digression for little gain. > And you force people to write buffer manipulation code so they realize how good people using other languages have it. Seems like a lot of time to spend to make a point that would have been a lot more relevant in 1990 than in 2016.
- CJefferson 10y agoExcept, undefined behaviour seems like mostly a C, and C derivates, concept. I teach C, and every year I have a number of students nearly in tears, because somewhere in the huge program they accidentally malloced sizeof(T*) instead of sizeof(T), but of course that causes a crash 10 minutes later in a totally different piece of the code base. My hope (it's not quite there yet, but getting closer) is that things like clang's sanitize modes will reach a point where any undefined behaviour immediately causes an abort. Then students can still figure out what they did wrong, but have a chance of finding the source of their bug.
- mdergosits 10y agoSometimes I use something like: #define ALLOC(n, type) (type)malloc(n sizeof(type)) which makes it harder to have those types of bugs, though not impossible.
- 9248 10y agoSpeaking as a past student I'm really glad I started with C. In the beginning, the fear of getting some random Segmentation fault out of nowhere actually taught me more than any textbook, school or best practices blog could ever do. It also forced me to learn how to use debuggers :)
- CJefferson 10y agoThat's what I tell my students, it's "character building", in the same way playing sports in the rain was as a child for me. Also, many students previously did a course on Java, and clearly never really understood the basics, it's much easier in Java to play "keep tweaking and fixing the exceptions until it works, then don't touch it", particularly for introductory-level projects.
- protomikron 10y agoShow them Valgrind. I think if one teaches C to newcomers it is an invaluable tool. If you compile via -g you get nice reports over undefined behaviour, memory leaks, etc. Really I wish I had access to it when I learned C.
- CJefferson 10y agoMy experience is that while valgrind is an amazing tool, it's actually not that great for new students. Sometimes it can be misleading, and it doesn't do stack tracking. It's hard to teach students not to over-rely on it, and trust everything it ever states. It seems best to first make them do some horrible debugging by themselves, and then move them onto valgrind late.
- protomikron 10y ago
- VLM 10y agoNone, so skip them. That's the cool part, algos don't necessarily require strings. Realize he's proposing first years where you have to LARP that they don't even know what an if-then-else construct is, or what is a function, or what is a loop, or what is recursion, or what is the concept of a memory map, or what is the concept of data or memory locations having a type (like float, long int, etc), or what is the concept of a variable. In 2016 most of them probably know, but schools feel the need to pretend. Also non-majors wanting a code experience will need an intro. This will make "real C programmers" very annoyed because OS code requires "real C skills" not a training wheels subset of C, but oh well. You can't really expect first year students to write OS code anyway. One hidden advantage is it would take enormous effort for a noob to put a C program on the internet, so this protects them from themselves until they pick up things in later higher level classes along the lines of buffer overflow protection and GIGO concept and unit testing and so on. If you teach them what is a variable, using framework-of-the-week, they're just going to get themselves or an employer powned thinking they know what they're doing after one class.
- pcwalton 10y agoIf you're skipping teaching strings because it's hard to work when them in the language you're using, you may want to consider whether you are actually doing students a favor, or whether you're trying to rationalize your decision to teach a language you happen to like.
- mike_hock 10y agoThe advantage of using C to teach algorithms and/or data structures is that it hides very little of what's actually going on, including allocations. "More code" correlates much more with "more work for the computer" than it does in higher-level languages. If you know what you'd have to do in C to implement a certain feature, you can guess what a high-level language is probably doing under the hood when you use its canned features.