Live data from Hacker News

Should you learn C to “learn how the computer works”?

words.steveklabnik.com

191–200 of 381 posts

Re: Should you learn C to “learn how the computer works”?

#191

C doesn't necessarily teach you how computers work. But it does teach you how software works. Our modern software empire is built on mountains of C, and deference to C is pervasive throughout higher-level software design. >You may have heard another slogan when talking about C: “C is portable assembler.” If you think about this slogan for a minute, you’ll also find that if it’s true, C cannot be how the computer work…

> Our modern software empire is built on mountains of C, and deference to C is pervasive throughout higher-level software design.

This I agree with and also I'd call the most important reason for Rust programmers to learn C. The C ABI is a lingua franca, not because it's good or pure but (as with spoken linguas franca) happened to be in the right place at the right time. It defines certain conventions and assumptions that didn't have to be assumed (implicit stack growth without declared bounds, single return value, NUL-terminated strings, etc.) and a lot of software is written to it, to the point that if you want your (e.g.) Python code and Rust code to interoperate, the easiest way is to get them to both speak C-compatible interfaces, even though you're not writing any actual C code.

Re: Should you learn C to “learn how the computer works”?

#192
post #75

Earlier quoted context omitted.

You can also learn that difference in something like C#. You don't need C for that. And C pretends there's a distinction between the stack & heap that doesn't actually exist. There is no significant difference there.

You're joking. There's a very serious distinction between the stack and the heap - perhaps they live in the same memory but they are used very differently and if you mix them up your things will break.

There is no hardware distinction between stack memory and heap memory.

In fact C teaches a model of a semi-standard virtual architecture - loosely based on the DEC PDP7 and/or PDP11 - which is long gone from real hardware.

Real hardware today has multiple abstraction layers under the assembly code, and all but the top layer is inaccessible.

So there's no single definitive model of "How computers work."

They work at whatever level of abstraction you need them to work. You should definitely be familiar with a good selection of levels - and unless you're doing chip design, they're all equally real.

Re: Should you learn C to “learn how the computer works”?

#193
post #140
post #68

Earlier quoted context omitted.

Except it isn't, not really. Even just the distinction between the stack & heap is wrong. They aren't different things, just different functions called on the otherwise identical memory. It's why things like Go work fine, because the stack isn't special. It's just memory. malloc & free are also totally divorced from how your program interacts with the OS memory allocator, even. GC'd languages don't necessarily sit on…

> Even just the distinction between the stack & heap is wrong. They aren't different things, just different functions called on the otherwise identical memory. It's why things like Go work fine, because the stack isn't special. It's just memory. To add to this: I have seen people who learned C and thought it to be "close to the metal" genuinely believe that stack memory was faster than heap memory. Not just allocatio…

Separate stack and data memory adress spaces will make the machine incompatible with ISO C due to impossibility to convert between "pointer to void" and "pointer to object". Code address space is allowed to be separate.

Re: Should you learn C to “learn how the computer works”?

#194

As someone who felt that C was the path to knowledge for how modern computer systems "work", Forth and QEMU have become my "stretch challenge" for those with the motivation to tinker. For me, working thru the resources on the OSDev wiki by taking jonesforth and linking it with the bootstrap from the "Writing an OS in Rust" tutorial ( https://os.phil-opp.com/ ) really showed me how far C is from the hardware, and how…

I agree about the benefits of a Forth-like language for tinkering. It's still very simple (like C), but the execution model is totally different, simpler, and more functional/mathematical.

I learned the HP programmable calculator version of Forth as one of my first languages, and I loved programming in that model. I think one's brain loses some flexibility if it hasn't programmed in a nonstandard model from an early time.

Re: Should you learn C to “learn how the computer works”?

#195

Earlier quoted context omitted.

It varies from application to application. In my domain, we reach for the CUDA libraries to write the high-performance parts of our code. ;)

That requires special Hardware in contrast to C code.

I spent like a thousand dollars on the box sitting under my desk; I'm pretty sure my C code runs on special hardware too. ;)

(and worth noting: if I pull out the special hardware you're thinking of from that box, my particular thousand-dollar-box is no longer able to run software I need because the GUI requires a graphics accelerator card. The OS authors have already reached for a subset of CUDA to optimize the parts of the GUI that needed optimization).

Re: Should you learn C to “learn how the computer works”?

#196

Technical nit: POSIX defines CHAR_BIT == 8 and on hardware where CHAR_BIT can be 16, 32 the alternative is to generate a lot of assembly (or just not work) to access 8 bits at a time. In my opinion everyone should learn assembly in combination with a simple language to understand how a computer works.

Technical nit on technical nit: I made no claims about POSIX in this post. You're 100% right though!

Re: Should you learn C to “learn how the computer works”?

#197
I liked the article. Many things mentioned there are inconvenient truths.

Claiming that a particular high level language must be learnt in order to understand how computers work is somewhat paradoxical - a hll is meant to abstract details, so if it helps understand the internals then it can't be a hll.

Also, the purpose of a programming language is not to teach how computer works; its purpose is to make computers do what we want. Its the steering wheel, gear stick and pedals of a car. If you want to know how a car works, you have to get out and look under the hood or slide underneath. Driving a manual transmission doesn't necessarily give any insight into workings of a car, except may be knowing that something like a clutch exists that is needed to be used to shift gears. Its your curiosity that makes you learn.

Re: Should you learn C to “learn how the computer works”?

#198
post #186

One valuable property of C that the author didn't hit, C code is easily translatable into assembler in your head. He kind of misses this point with the virtual machine discussion. Yes C code becomes different types of assembly by platform, but you can look at C and have a clear idea of what the assembly will look like. This is at a really good level for driving intuitions about what the computer is actually doing. Yo…

There is an article about this. 'C Is Not a Low-level Language'.

https://queue.acm.org/detail.cfm?id=3212479

Re: Should you learn C to “learn how the computer works”?

#199

C... IDK. Maybe. But, pointers yes definitely. Even some assembly. You really should understand how things like .size or lengh() aren’t “free” and how they work.

I think I may miss your meaning. In what sense is .size or length() not "free?" At some point, some O(n) work was done somewhere to construct the n-element structure we're getting size on, but I don't think I've ever encountered a core library that implements .size as anything other than "Look up the cached length value that I computed the last time my length changed."

C strings do not have a cached length.

This is one of their largest weaknesses, which is why many other languages do not use C strings.

Re: Should you learn C to “learn how the computer works”?

#200

Earlier quoted context omitted.

Just playing devil's advocate here... why is this such a "crucial" concept, for someone who is using a higher level language (like Python or Ruby)? If 99% of what that person does is gluing together APIs and software modules, and they can see their memory usages are well within range, why does it matter?

true. it's like interior decorator vs. interior designer if you're just going to move couches around and put down throw pillows, who cares about a solid foundation of design fundamentals and architectural psychology.

It's also like fluid dynamicist vs quantum physicists. If you're just going to move oil around and put down differential equations, who cares about a solid foundation of quantum gravity and chromodynamics.
Post reply on HN