4 ms·
I don’t think this is true. Check this post out - Should you learn C to "learn how the computer works"? (https://steveklabnik.com/writing/should-you-learn-c-to
by nindalf 4y ago
I don’t think this is true.
Check this post out - Should you learn C to "learn how the computer works"? (https://steveklabnik.com/writing/should-you-learn-c-to-learn-how-the-computer-works https://steveklabnik.com/writing/should-you-learn-c-to-learn...). Spoiler alert - no.
- dijit 4y agoSteve Klabnik has done a lot for systems programming and that post is a lot more even-handed than you're suggesting. If, however, we're talking about the kernel then perhaps we should listen to what Torvalds says about this topic. "People who designed C, designed it at a time where the language had to be geared towards the output, so when I read C I can think about the Assembly that it will create": http://www.youtube.com/watch?v=MShbP3OpASA&t=20m45s http://www.youtube.com/watch?v=MShbP3OpASA&t=20m45s Consider that he said this in a time with C++, even if Rust was in its infancy: it is not as tied to the assembly it produces. Not by a long shot.
- TrickardRixx 4y agoSounds to me like if I want to know "how computers think" I should learn assembly.
- dijit 4y agoI know you're trying to be a smart-arse; but by virtue of using C you will learn Assembly. The issue with Assembly directly is that it's absurdly non-portable, too low level and too unstructured to do anything reasonable with it. There's a reason that Linux is written in C and not ASM Directly.
- UncleMeat 4y ago> by virtue of using C you will learn Assembly. I don't believe this at all. You won't learn how to deal with limited numbers of registers. You won't learn about method prologues and epilogues. You won't learn about oodles of stuff.
- Jensson 4y ago> You won't learn how to deal with limited numbers of registers. You won't learn about method prologues and epilogues. Those things takes like an hour to learn, translating C to assembly is trivial, it takes time and will be verbose but it isn't hard at all. So even though you don't learn all the details you still learn all the higher level stuff related to assembly programming when you program in C. This isn't true for other languages, translating arbitrary C++ or Java or Javascript to assembly is really hard, so they don't teach you to think like an assembly programmer.
- dijit 4y ago> deal with limited numbers of registers I mean; you will likely end up stepping through debuggers where you will see registers being used. At least if you learned C like I learned C. Similarly for Prologue and Epilogue. "why does a function call have a cost" is a common question and it's solved forever after an hour googling.
- jcranmer 4y ago> by virtue of using C you will learn Assembly. Even interpreting this as charitably as possible--that you don't mean literally learning assembly but rather learning everything besides specific assembly syntax that you would have picked up from learning assembly--this claim doesn't hold water. For starters, C isn't that much closer to hardware than, say, Java. The main differences you have with C are that a) C has a pointers-are-almost-integers model [1] and b) C has a more limited runtime than other languages. C is still a fundamentally based on an abstract machine semantics model, and that abstract machine doesn't have a close bearing on modern hardware. In particular, C does not distinguish between registers and memory, and if I had to pick the single most salient feature of modern hardware you need to understand well to be able to say you understand how computers work, it's the register/memory distinction. If you think processors are mostly like they were in the 1970s--when you could say "add 1 to this memory location"--then C's shrugging off the register/memory distinction makes sense, but this is a situation that hasn't been true for several decades. Another failure of C is that it's far less expressive than assembly. There are features in other languages that are impossible to express in C. How do you write a function with multiple entry points, as you can in Fortran? Or a coroutine, as you can in Algol? Or nested functions, as in Pascal? Or try-catch, as in C++? Or functions with multiple return values, as in Matlab? Indeed, how do you write something like JMP *reg in C, a useful primitive for state machines? No, C does not come close to being a good description of modern processors, where "modern" means "anything that came out since I was born." [1] Not going to open up the can of worms that is pointer provenance.
- cesarb 4y ago> C does not distinguish between registers and memory Just nitpicking, but doesn't C have the register keyword? (I know it does nothing at all nowadays, but AFAIK it did make a slight difference back in the dark ages.)
- jcranmer 4y agoConsidering that `volatile register _Atomic int x;` is a totally legal statement, and two [1] of those keywords have semantics that are only relevant for memory operations, I'd say that the "register" keyword isn't sufficient to distinguish register from memory. [1] Okay, the official semantics of "volatile" strictly speaking are completely orthogonal to memory, but the practical effect that everyone agrees on (don't optimize this memory access) is inherently oriented towards memory, and the fact that the semantics are so vague about what it actually does is partially a reflection of the fact the semantics themselves don't distinguish between register and memory.
- kjeetgill 4y ago> C is not “how the computer works.” I don’t think most people mean this phrase literally, so that is sort of irrelevant. Understanding the context means that learning C for this reason may still be a good idea for you, depending on your objectives. I think summarizing that article as "no" really undercuts how diplomatic and reasonable Steve Klabnik is in it.
- nindalf 4y agoOf course learning widely used technologies may be a good idea for some people, depending on their objectives. That’s a truism. But is it necessary to understand now a computer works? No. You can also check out "C is how the computer works" is a dangerous mindset for C programmers (https://steveklabnik.com/writing/c-is-how-the-computer-works-is-a-dangerous-mindset-for-c-programmers https://steveklabnik.com/writing/c-is-how-the-computer-works...)
- steveklabnik 4y agoThank you for the kind words. I got enough heat for it at the time that it took me a full year to return to the topic, so it's nice that some folks still remember it fondly.
- cannabis_sam 4y agoYour views on programming languages are deeply appreciated, regardless of whether I agree or not.