4 ms·
This is an interesting idea. For one of the first year programming courses here at UWaterloo, we start by teaching students Racket. To ease them into C, we use
by michaelmior 10y ago
This is an interesting idea. For one of the first year programming courses here at UWaterloo, we start by teaching students Racket. To ease them into C, we use a subset we refer to as "functional C."[0] This is really just C with a few restrictions. The main ones are that all "variables" and parameters must be const and all branches of an if statement must return a value.
While these restrictions may seem silly to the HN crowd, it leads to an interesting way of thinking about solving problems.
[0] https://www.student.cs.uwaterloo.ca/~cs136/handouts/03-functional-c-post.pdf https://www.student.cs.uwaterloo.ca/~cs136/handouts/03-funct...
- jrajav 10y agoInteresting! On the other side of the world, those are precisely the main two restrictions we follow in JavaScript in our React projects right now in order to make our components more functional and predictable. It's amazing how much maintainability mileage you can get out of a few simple rules.
- e12e 10y ago> and all branches of an if statement must return a value. Is indeed a bit strange. I guess I can see the reasoning, though. "const by default" doesn't seem all that unreasonable to me - isn't that one of the major driving forces we're seeing in "new" languages - that based on years of experience, "accidental" mutability should be avoided -- mutability should not be the default? How does this subsetting of C affect the error messages the students are (most) likely to see? Does -Wall typically catch treating a const as mutable? (I assume so, I'm just curious about this, as I'll soon be teaching a beginning programming course - and a sub-set of C might be an interesting option).
- michaelmior 10y agoWe are pretty liberal with the warnings. -Wall will catch trying to mutate const variables. We also use address sanitizer[0] with clang which helps a lot with common memory errors. All this makes the code run (relatively) quite slow but since anything they're testing should complete in a few seconds regardless, it's not a problem for us in practice. [0] http://clang.llvm.org/docs/AddressSanitizer.html http://clang.llvm.org/docs/AddressSanitizer.html