7 ms·
It is silly to start teaching in C. You must first learn assembler and then you understand the godsend that C is. When you write C, you should be thiking what
by enriquto 8y ago
It is silly to start teaching in C. You must first learn assembler and then you understand the godsend that C is. When you write C, you should be thiking what happens in assembler, and then writing it beautifylly in C.
In parallel to this low-level thread of learning, you have to learn other high-level languages, of course.
- FranzFerdiNaN 8y agoThis is just as dumb as learning C first before picking up Python or Java, just to appreciate what those languages do for you.
- paulriddle 8y agoHe is commiting basic fallacy which is when you discovered some benefit of learning something related to X, you want to tell everybody to learn it before they start learning X. It so common in programming discussions. It is a fallacy because oftentimes you can't appreciate something until you have a need for that or geniune curiosity.
- enriquto 8y agoI actually learnt assembler after a being able to code in a few high-level languages. Assembler was a sort of "liberation", an exhilarating feeling of understanding "so, that's it!". Even if you do not spend much time in assembler, being able to write a hello world and a program that prints prime numbers (or some graphical demo) is a valuable knowledge in computing. Programming without knowing anything about assembler is like driving without having ever opened the hood of your car and changed some oil. Of course, if you are a professional driver you will have specialist mechanicians that take care of all of it, but still it would be ridiculous if you could not do a few simple things.
- paulriddle 8y ago> being able to write a hello world and a program that prints prime numbers (or some graphical demo) is a valuable knowledge in computing. You are so wrong. It is not valueable at all. If you are able to do this, then you're just capable of signaling that you have been exposed to assembly and familiar with the very basics of it. But how is it any useful? If you could find some intricate bug, or optimize a program in a considerable way based on insight you gained from reading it's assembly code that would have been very valueable indeed.
- enriquto 8y agoYou know, serious biologists must know some basic chemistry, and serious chemists must know some basic physics.
- de_watcher 8y agoFirst you need something like a simple Pascal. Otherwise you've got C that crashes all the time or you're stuck with some environment too opinionated about GC/references and a way of least resistance to put everything into its specific weird structures.
- pjmlp 8y agoGood option, ISO Extended Pascal has all the features as ISO C, while providing an easier path into learning about pointers and low level coding. Plus dialects like Object Pascal and Free Pascal provide a couple of niceties as well.
- cm2187 8y agoAnd you will have disgusted half of the class from programming by the end of your first assembler lecture. Something similar happened to me in a general engineering curriculum where our introduction to programming was in C on some old unix machines that were already already very obsolete (as of end of 90s), with no more IDE or debugger than the equivalent of notepad and debug by printf. I thought it was interesting but too tedious for my taste (I had never heard of IDEs and debuggers). It's only years later that I went back to programming, from higher level languages, and progressively making my way into more sophisticated / lower level languages. You don't teach kids math by starting with topology. Most 1st year university students will have never programmed in their life (particularly if all they dealt in their life was smartphones and tablets).
- enriquto 8y agoI did not say that you start programming in assembler. I just said that it is better to learn some assembler first if you need to learn C.
- dgacmu 8y agoWe (CMU) respectfully disagree, and we turn out some damn fine programmers. Python -> A restricted C subset ; standard ML -> asm Teaching fun and power first is good for engagement. Teaching how to think and structure is good for later asm experience so people have an existing concept of how to turn problems into solutions in code.
- golergka 8y ago> Most 1st year university students will have never programmed in their life What? That's completely untypical for me - I would expect that in a university with decent admission competition (don't know how these things work in US exactly) students that get in know at least a couple of high-level programming languages in addition to taking part in programming competition and general geekiness like brainfuck.
- cm2187 8y ago
- tryum 8y agoThis is silly to start teaching assembler, You must first learn nand gates ;)
- pjmlp 8y agoActually on my university we had digital circuit design one year before Assembly classes. And many universities do follow books like "From NAND 2 Tetris".
- jabl 8y agoThis is silly to start teaching nand gates, you must first learn semiconductor physics ;) But to understand semiconductors you first need to understand quantum mechanics. And to understand QM you first need to understand classical physics. Oops, I think we just ran out of time for a masters program. ;)
- userbinator 8y agoYou can make gates out of more than just electronics (mechanical, electromechanical, pneumatic, hydraulic computers all exist), hence the suggestion to start there --- the abstraction doesn't really leak.
- pjc50 8y agoThe hydraulics will probably start leaking. More seriously, it is possible to fit quite a lot of this stuff into an undergrad program - my Cambridge degree included logic gates (including drawing silicon layout with coloured pens), computer architecture (ARM assembler), a lab on FPGAs, Java, Standard ML (for type inference and lambda calculus), and had plenty of time left over for higher level topics. Current syllabus: https://www.cl.cam.ac.uk/teaching/1819/cst.pdf https://www.cl.cam.ac.uk/teaching/1819/cst.pdf (one term = 8 weeks)
- loup-vaillant 8y agoThat's how you end up with student believing dangerous falsehoods "signed integers are 2's complement". This is true in x86, ARM, RISC-V, and just about any architecture I can think of, but it is not quite true in C, even when it is implemented on top of a 2's complement architecture. Signed integer overflow is undefined, you have to explicitly convert to unsigned before you do any overflow. Only then do you get the implementation defined behaviour your sought, instead of the usual nasal demons. Also, assembly doesn't mean much with out of order cores. Data dependencies are likely more important than the generated assembly.
- enriquto 8y ago> That's how you end up with student believing dangerous falsehoods "signed integers are 2's complement". 100% agree that this is a dangerous falsehood. I would add the word "always" in your sentence to clarify its falsehood. But there is an even more dangerous, and more insiduous falsehood: "integers are encoded in some mysterious way that is useless to know".
- jandrese 8y agoI wonder how much heartache it would be for the next revision of the C standard to go: Integers behave as if they were two's complement for all overflow behavior. It's already true in just about every system in the world today, and people with extremely obscure hardware can just hack a workaround into their compiler (or straight up ignore the standard because they're just a handful of people anyway). I get that back in the day the K&R didn't want to impose on the hardware vendors and left the standard vague where they had different ideas, but that doesn't mean you can't evolve the standard as the hardware evolves over the decades.
- loup-vaillant 8y agoWhy is this getting downvoted? It sounds very reasonable to me. It wouldn't even be the first time C breaks compatibility (I'm thinking of strict aliasing).
- 8y ago
- jcranmer 8y ago> When you write C, you should be thiking what happens in assembler, and then writing it beautifylly in C. That is a horrible, horrible idea. It gives people the misrepresentation that C is really "just" a thin veneer over assembly language, which it most certainly has not been for at least 20 years. Moreover, it feeds the cult of C, the idea that C is the only language capable of being close to the hardware and that other languages or attempts to build system-level languages need not apply. C has lots of flaws and faults in the language, but we're not going to be able to make any progress in fixing the language, or more likely replacing it with a better language, if we continue acting as if it is the only way to get low-level access to the hardware.
- yourbandsucks 8y agoI'd offer a different perspective: C is a simple language that obviously maps to a programmer's idea of the assembly they'd write. It biases towards lots of fixed-size stack frames and fixed-layout structs. Writing C code really does feel very close to the "bounded turing machine" metaphor that the CPU gives us. Other languages have their advantages, but C's proximity to assembler, with all the faults included, really is a great pedagogical tool.
- jcranmer 8y ago> C is a simple language that obviously maps to a programmer's idea of the assembly they'd write. It's not. That's my point. You don't need undefined behavior to get to that point, just consider what assembly you get from this code: unsigned prog_a(unsigned a) { return a * 2; } unsigned prog_b(unsigned a) { return a / 3; } What do you think you're going to get for that code? The "obvious mapping" principle for both codes suggest you're going to get a multiply and a division instruction, respectively. On x86, however, what you get is this: prog_a: leal (%rdi, %rdi), %eax ret prog_b: movl %edi, %eax movl $-1431655765, %edx mull %edx shrl %edx movl %edx, %eax ret In other words, the first program turned into a load-effective address instruction, and the latter turned into a multiply-hi instruction. Even something as simple as basic arithmetic gets turned into weird instructions, and which ones get this treatment is essentially a game of roulette based on compiler optimizations and particularly heuristics. We're not even bringing undefined behavior into play here, which is usually the major objection to C-obviously-maps-to-assembly; it's falling flat enough without it. The primary advantage C brings, what people are really touting when they tout its proximity to assembly, isn't that it's close to assembly but that it has a well-known, stable ABI for that mapping. Of course, it turns out that said ABI is actually a bad idea if you want performant modern code on most architectures (the infamous array-of-struct versus struct-of-array problem).
- jhallenworld 8y agoThere is one specific reason why assembly language is a good idea to help with C: pointers. Many students have trouble with them. The idea of storing an address in a register is the same as loading a pointer into an automatic variable. Pointer indirection is the same as assembly load or store register indirect.