Live data from Hacker News

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

words.steveklabnik.com

91–100 of 381 posts

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

#91

Earlier quoted context omitted.

> The way a computer works is based off of transistors and some concepts built on top of that (ALUs for example). However, there is no need to know about any of that because you're presented with an abstraction (assembly). I'd argue you should know how that works. Cache-misses, pipelining and all these subtle performance intricacies that seem to have no rhyme or reason just fall out out understanding exactly how you…

I'd argue that you shouldn't be driving a car unless you've rebuilt a transmission yourself, but that argument wouldn't go far.

That'd be like saying your end user should understand cache misses, however if you're starting a car design/repair shop you might want to know about how transmissions work.

The primary reason for dropping down to native is to get better performance. If you're going to do that you'll leave 10x-50x performance on the table if you don't understand cache misses, prefetching and the other things that manual memory placement open up.

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

#92
post #53

I stopped reading when I got to "C also operates inside of a virtual machine." Is the author confusing virtual memory with virtual machine? Perhaps they're referring to the way a high level language abstracts away the details of the H/W. I didn't care enough to read on. That said, I learned the most about "how a computer works" in a class that taught Intel 8080 assembler on a system running CP/M. (Technically it was…

> I stopped reading when I got to "C also operates inside of a virtual machine."

Then you missed my actual explanation and description, which is described in the rest of the post. Since others are also apparently confused, I'll re-state it here.

The C language is not defined in terms of hardware. The C language is defined in terms of an "abstract machine." This machine, being abstract, does not exist. "Virtual" and "abstract" are terms that are broadly speaking synonyms in general usage.

The spec even defines this in terms of an "execution environment" which can be "freestanding" or "hosted", and most C programs are, in the spec's language, running in the execution environment of C's hosted, abstract machine.

The rest of the post is exploring how this is conceptually the same, but different in details, than something like the JVM, which is what many people think of when they hear "virtual machine." As mentioned elsewhere in the thread, the sense of "virtual machine" that C uses is where LLVM gets its name from, yet people found that confusing enough that they changed the name.

This comment is also a re-statement of my point, maybe it helps: https://news.ycombinator.com/item?id=18123642

You may also argue that the abstract machine is practically insignificant. I disagree, but that's what my follow-up posts are about, so this post doesn't address this question directly at all.

Does that help?

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

#94
post #86

C conceptually is the nearest layer to the hardware that you'll get outside assembler. What that means is that most C operations can be easily translated into the machine code equivalents and that makes debugging of compiled code so much easier. A disassembly of many binaries will reveal their C roots by function calls being equivalent to jump statements, as an example. If you have the C source then you can usually f…

> What that means is that most C operations can be easily translated into the machine code equivalents and that makes debugging of compiled code so much easier. A disassembly of many binaries will reveal their C roots by function calls being equivalent to jump statements, as an example. If you have the C source then you can usually figure out what's going on. This is very much not true in my experience. Optimization…

Why would you turn on optimization while debugging?

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

#95
post #58

Earlier quoted context omitted.

C at the very least teaches the difference between stack and heap memory, a crucial concept obscured by most higher-level languages.

Or passing by value vs passing a pointer, or the importance of memory management... Modern languages solve problems created developing in legacy languages (primarily C). The issue is that knowing a solution without knowing the prior problem which the solution addresses, doesn't really lend itself to clarity.

Memory management in C is very different than memory management in JavaScript, which throws exceptions when you try to access invalid memory, but will gladly let you create memory leaks inside event callbacks or other loops and keep chugging along gladly until it can't anymore. Writing a safe, efficient, high performing JavaScript app is very different than writing the same thing in C, and although I know both deeply well, I don't think learning C has helped me write better JS.

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

#96
post #69

I definitely would not consider a CS education complete without C. If you don't know C, that means you don't know how how parts of operating systems work. It definitely makes you a less useful engineer. I don't think people need to be able to code in C at the drop of a hat. But it should not be a scary thing for good engineers.

When I started my CS degree most home OS were still mostly written in Assembly, and on my geography Turbo Pascal was the language to go when Assembly wasn't required.

My university introductory classes were Pascal and C++.

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

#97
post #86

Earlier quoted context omitted.

> What that means is that most C operations can be easily translated into the machine code equivalents and that makes debugging of compiled code so much easier. A disassembly of many binaries will reveal their C roots by function calls being equivalent to jump statements, as an example. If you have the C source then you can usually figure out what's going on. This is very much not true in my experience. Optimization…

Why would you turn on optimization while debugging?

Sometimes the bugs don't happen when optimizations are off. (-:

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

#98

Earlier quoted context omitted.

This thread apparently started out as a misunderstanding, but just to show how free this can be: https://godbolt.org/z/7ehDPx

I think you replied to the wrong post! (Thanks for the nice article btw.)

Gah, you're right. Too many tabs. Thanks and you're welcome :)

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

#99

Learning C really helped demystify a lot of what used to seem like magic that higher level languages do, like memory management for starters.

You mean like this?

    var
      ptr : pointer to integer;

    begin
      New(ptr);
      ptr^ = 23;
      Dispose(ptr)
    end;

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

#100
post #63

Earlier quoted context omitted.

But in addition to the mismatch between the abstractions provided and the real hardware, C qua C is missing a huge number of abstractions that are how real hardware works, especially if we pick C99 as Steve did, which doesn't have threading since that came later. I don't think it has any support for any sort of vector instruction (MMX and its followons), it doesn't know anything about your graphics card which by raw…

A computer does not need to implement a stack What general purpose computer exists that doesn't have a stack? Push/pop have been fundamental to all the architectures I've used.

I don't have direct experience, but I believe that system/360 programs have historically not had stacks, opting instead for a statically allocated 'program save area'.

https://people.cs.clemson.edu/~mark/subroutines/s360.html

XPLINK, a different linkage convention, also for MVS, does have use a stack-based convention:

https://www.ibm.com/support/knowledgecenter/en/SSLTBW_2.2.0/...

Post reply on HN