11 ms·
C0, an Imperative Programming Language for Novice Computer Scientists (2010) [pdf]
- azhenley 9y agoDoes anyone know of a website containing resources for teaching this? I'd also be interested in seeing who is using it now a days.
- 0xd3adbeef 9y ago15-122, an introductory programming course at CMU, uses C0 for most of the course. Lecture notes are available on the site: http://www.cs.cmu.edu/~15122/schedule.shtml http://www.cs.cmu.edu/~15122/schedule.shtml
- hackermailman 9y agoalso their compiler course you implement a compiler for C0 http://www.cs.cmu.edu/~rjsimmon/15411-f15/schedule.html http://www.cs.cmu.edu/~rjsimmon/15411-f15/schedule.html
- dasimon 9y agoHello, I'm a TA for the intro course taught in C0. C0-specific resources can be found at http://c0.typesafety.net http://c0.typesafety.net
- baldfat 9y agoHere is the Tutorial Wiki
- Avshalom 9y agoI mean I get the idea but No floating point datatypes No ... switch statements or do...while loops seem like terrible things to leave out, occasional gotchas of floating point not with standing being only integers means no division
- lou1306 9y agoNo floating point types is a little harsh, but IMHO one should only use them when they really understand their implications. Otherwise they might be tempted to do Bad Stuff like using float for currencies, etc.
- instruction-ptr 9y ago“No division”? How do you reason this? Integer division is a thing
- Avshalom 9y agodivision is not defined on the set of integers, you only have modular arithmetic.
- instruction-ptr 9y agoSee section 7 of http://www.cs.cmu.edu/~15122/handouts/02-ints.pdf http://www.cs.cmu.edu/~15122/handouts/02-ints.pdf (As an aside nearly every language defines division on the set of integers this way so it’s not even like we’re making this up)
- jameshart 9y agodivision is also not defined on the set of IEEE binary floating point numbers, you only have (well-defined) rounding. For that matter, addition and subtraction aren't defined on the range of fixed-bit-width integers.
- recursive 9y agoIt is defined and you can do it in C without using floats. On the other hand, even if you do use floats, arbitrary arithmetic is not invertible. In other words a / b * b isn't necessarily a, regardless of what types they are.
- baby 9y agoWhat do you mean division is not defined on the set of integers? Mathematically or programmatically? Because yes you have euclidean divisions which are divisions for the integers.
- Shoop 9y agoHere is some more information about C0: C0 is used in 15-122, Carnegie Mellon's second semester introductory programming class. I am currently taking this class. The class teaches C0 for the first two thirds of the semester and then transitions to C for the final part of the semester. C0 has essentially the same syntax as C, but for pedagogical purposes the semantics of the language have been changed to be much more similar to java. Instead of manual memory management, there is a garbage collector, and user defined structs can only be allocated on the heap. Additionally, there is only one integer type which is a signed 32-bit two's complement integer. Overflow is defined as wrapping. strings are opaque immutable types implemented at a language level, rather than just null-terminated buffers. C0 catches out of bounds array accesses at run time. While C0 internally stores array lengths to perform this check, the length is not accessible from C0 code so array lengths must be passed around just the same as C. C0's biggest feature beyond C is that it allows for contracts. Functions can have preconditions and postconditions. There are also loop invariant contracts and assertions. These contracts are checked at run time when specific flag is passed to the compiler or interpreter (C0 has both, and uses a bytecode internally). A major focus of the class is proving the safety and correctness of the programs we write using these contracts. We are encouraged to prove safety and correctness using only logical reasoning from contract to contract, not operational reasoning. A co-requisite of the class is a course in proofs. There seems to be a heavy influence on the teaching style from Dijkstra's "On the cruelty of really teaching computing science" [1]. The 15-122 class has written assignments focusing on the proofs part of the course and programming assignments which for the most part are automatically graded by autolab [5]. Our code is tested against a number of unit tests to ensure its correctness and our contracts are also tested to see if they can catch bugs in faulty implementations. C0's implementation is not open source, but it appears to be used in ongoing research [2]. Here is the language website and course website [3], [4]. [1] https://www.cs.utexas.edu/~EWD/transcriptions/EWD10xx/EWD1036.html https://www.cs.utexas.edu/~EWD/transcriptions/EWD10xx/EWD103... [2] http://www.cs.cmu.edu/~fp/papers/cc016.pdf http://www.cs.cmu.edu/~fp/papers/cc016.pdf [3] http://c0.typesafety.net/ http://c0.typesafety.net/ [4] http://www.cs.cmu.edu/~15122/ http://www.cs.cmu.edu/~15122/ [5] http://www.autolabproject.com/ http://www.autolabproject.com/
- acmustudent 9y ago
- deleted 9y ago[deleted]
- thecompilr 9y agoC language is as simple as it gets. The only concept people struggle with is pointers, but even that is a very simple concept. Teaching something that is simpler than C to computer scientists will breed very poor engineers.
- CodesInChaos 9y agoC is a very tricky language, because a lot of constructs that work when naively translated to assembly (on common CPUs like x86 or ARM) are actually undefined behaviour.
- fpig 9y agoThis is always brought up when "difficulty" of C for teaching is discussed but it will basically never be an issue in a programming college course. It is a problem that doesn't exist.
- flafla2 9y agoI am currently a TA for 15-122 at Carnegie Mellon, the class that C0 was originally made for. I would argue that C0 does an excellent job at breeding good programmers because of the following features: 1. Contracts in C0 bake preconditions, post conditions, and loop invariants right into the language. Contracts are only checked when in "dynamic recompilation" mode (basically debug mode). This allows you to check the correctness of your code more easily (and, importantly, in an easily gradable way). 2. The language is designed in such a way to introduce C to programmers that are used to other higher level languages. In the C0 phase of the course we introduce students to fundamental concepts like memory allocation, code reasoning and contracts, binary representations of numbers, and unit testing. Next we transition to C1 (included in the C0 install) which introduces typedefs and other features of C. At this point we focus on introducing data structures. Finally we make the final transition to C, where we talk about undefined behavior, gcc, stack vs heap, etc. I've taken this course myself, and I would argue that this measured approach to learning C is far superior to throwing students (most of whom have no low-level programming experience) straight into C.
- 9y ago
- lmm 9y agoIf you're willing to break compatibility with C, why not make a clean break and use a language that better supports the things you want? The authors go on (correctly) at great length about the difficulty of union types in C compared to an ML-family language; why not use an ML-family language? (My university used Standard ML for their first programming course and I see it as a good choice)
- instruction-ptr 9y agoThe course that uses C0 goes on later to C, and is literally titled “Principles Of Imperative Computation”. We use Standard ML for “Introduction to Functional Programming”. - source: I’m a TA for this course
- murph-almighty 9y agoI was an ECE and now regret not taking Intro To Functional Programming (I almost typed 150 by instinct). I was put off by the horror stories, and perhaps also by a lab I saw once that was basically a longform story about "pleasing Senpai". My iteration of Principles of Imperative Computation was... something. I liked the course but the professors who ran it that semester were really unpleasant. They accused a friend of mine for cheating when she pointed out an obvious mistake in someone's code during office hours when the line for TA help was basically on two whiteboards. She became a TA the following semester. ¯\_(ツ)_/¯
- instruction-ptr 9y agoAlso - we don’t break complete compatibility with C. We just restrict the amount of C things they are allowed to use
- fpig 9y agoI thought this would be for kids, I don't see the point of a simplified language for college students. However, if they as someone said use it in a compiler-writing course, for that purpose it makes sense to have a simplified language. I had to do that back in college and basically used a C subset for it (for the compiled language, not the implementation language).
- marcosdumay 9y agoIt is garbage collected, and includes both a heap of safety features and better compiler messages. This is a very nice set of features for people learning about data structures and memory management.
- grayhatter 9y agoNo it's not, it's training wheels. It's great for children, not college students. C + a address sanitizer is better for learning about data safety.
- roywiggins 9y agoNot everyone comes into college with extensive programming experience.
- marcosdumay 9y agoWell, it is training wheels. The paper also argues that they should be removed, as students are expected to migrate to C during the course. It also does not make for a good language for the first introduction to programing. But if you structure your courses like the OP does, it's a great language to have.
- kthejoker2 9y agoLol children, how privileged are you? Half of America's children grow up with zero computers in their home, much less developing nations.
- instruction-ptr 9y ago
- dbcurtis 9y agoC with training wheels? So it seems to me that this course is trying to accomplish two things that are mostly orthogonal: 1) teach principles of computation, 2) teach where the semicolons and curly braces go. #2 is a valid goal if you eventually want to ramp someone up on C/C++ without suffering language switching turbulence. But overall, I would expect that an intro course should be teaching fundamentals first. Language syntax is a completely secondary issue with respect to learning good imperative programming practices. Languages come and go. Semicolons come and go. Yes, language switching causes speed bumps, I switch between C (embedded) and Python regularly. Twitchy-semicolon-pinky is a thing. Inventing another language to teach the basic corpus of imperative programming ideas seems like a lot of effort for little lasting payoff.
- hackermailman 9y agoThe course it was made for at CMU (15-122) is primarily about writing contracts for imperative programs, I guess they decided C0 was the best way to do that since students have to take C anyway in 15-213 afterwards. Robert Harper's blog he apparently pushed for freshmen to land directly in a SML course where they would learn both imperative and functional methods but for legacy reasons they all agreed C should still be taught but with an emphasis on correctness/contracts so C0 was born.
- tinalumfoil 9y agoAlthough I learned to program past when it was popular, I can't shake the feeling that BASIC is the best way to teach programming. The basis of any computer is the sequential execution of instructions, and it's this model of computation that informs things like algorithmic complexity or Turing completeness. Even if teaching BASIC wasn't possible, I would still prefer to see a subset of x86 assembly taught than something ridiculous like "a simpler C" which obscures the core functionality of a computer with abstractions, without teaching a practical language.
- deaddodo 9y agoThe funny thing about BASIC is that it's MUCH closer to assembler (and, by extension, the logic of the CPU) than any other language. It gets a lot of flak for GOTO's and the like, but that's how you control logic flow in assembly. C is an abstraction that allows you to avoid control statements like GOTO and every higher level language just abstracts more away from you (memory management, static variables, strongly typed variables, etc)
- JTbane 9y agoOne can see why they chose a more-safe version of C for an intro course- beginner C programmers can fall into a wide variety of difficult to debug pitfalls (memory leaks, out of bounds reads and writes, undefined behavior) that can make the task of teaching and grading a nightmare. My university opted to use C++ as the introductory programming language, since it is somewhat more safe. Now they are transitioning to even safer languages like Python and Javascript. While I don't agree with it, I can see why it is necessary to reduce the headache for instructors. C0 seems like a good tool to use for teaching, although it may lead to bad habits later. To wrap it up, in my opinion students should definitely be exposed to the concepts of the C family of languages early on: imperative programming, pointers, dynamic memory allocation, et cetera. All the pitfalls associated with these concepts also need to be explored. The language doesn't necessarily matter as long as the students are allowed to make mistakes and learn from them.
- SeanDav 9y agoI would have thought that Pascal is a great candidate for a simpler, safer language that still has enough features to write serious applications.
- macintux 9y agoFor everyone complaining about how they taught themselves pointers while in diapers so why can't college freshmen already do this stuff... 1st: Restricting the set of students who can succeed in CS 101 to those who have already done extensive programming is one way to make sure the field never diversifies. 2nd: Computer science is not (supposed to be) about programming. Let's teach them how to think before we teach them how to be language lawyers.
- norswap 9y agoBut should a language based on C -- of all things, be taught? I suspect they do this to transition students to real C later... Won't that give them bad habits later down the line? Seems like a lot of work just to avoid going with Java or Go. With Java, eschew inheritance (not a bad habit at all) and wildcards at first, and you're fine.
- khedoros1 9y ago> But should a language based on C -- of all things, be taught? Why not? This variant is garbage collected, has array bounds checking, and doesn't allow C's undefined/unspecified behaviors.
- mac01021 9y agoComputer science is (and must be) about programming. It need not be about C, or present-day digital computers, or even anything to do with the von Neumann model. But there must always be a formal notation for describing computations, and students of Computer Science must always learn to treat that notation with rigor and come to grips with its nuances. Probably too they must always deal with the concept of indirection, and think about references to (objects that contain) other references. I'll grant you, though, a language with a saner notation for describing pointers (and types in general) would be easier to learn than C, and could still be equally useful - if not moreso.
- macintux 9y agoProgramming is a critical tool, but computer science isn't about programming any more than physics is about advanced mathematics.
- ExceptionRaised 9y agoHere's an interesting extension to the language to allow for session-typed concurrency. [0]: http://mwillsey.com/papers/cc0-thesis.pdf http://mwillsey.com/papers/cc0-thesis.pdf
- augustk 9y agoWhy not use Oberon instead?
- pklausler 9y agoUsing a weird local subset of C as an introductory imperative programming language seems like a really bad idea to me, unless you're using your weird local subset of C as the source language for a compiler construction course. There's just so many other good options.
- murph-almighty 9y agoI was an ECE major at CMU. C0 basically served as an introduction to C, with contract annotations. The contract annotations were used to enforce more thinking about your code (i.e. proving your code worked via pre/post/loop conditions). There were still pointers, there was just a bit of syntactic sugar surrounding it. About 2/3's through the course we switched to full-blown C, at which point we had to learn pointers. The intro to computer systems course (think malloc, proxy, and buffer overflow labs) used C as well, and that in turn required us to use pointers. There's no "losing out" on learning pointers. It's basically a step-stool to C. At the time, I had a pretty good grasp of pointers and thought C0 was a bit silly- I'd never used contracts in my life. I currently work as a full-stack web developer (bit of a twist from my intended path) and I've never seen anyone "write out contracts" like I did in C0. I now think it was a valuable exercise in that it forces you to define the parameters that allow your code to run.
- bwasti 9y agothe CS department also offers a compiler class that has you write a compiler for C0: https://www.cs.cmu.edu/~fp/courses/15411-f13/resources.html https://www.cs.cmu.edu/~fp/courses/15411-f13/resources.html