Live data from Hacker News

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

words.steveklabnik.com

101–110 of 381 posts

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

#101

Earlier quoted context omitted.

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 placeme…

I'm not going to play anymore metaphor/semantic games. It's nice that you did that project, but it's not at all necessary for someone to engage in that in order to understand performance issues.

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

#103
post #66

You should learn C to learn what every language is loosely based on and what unrestricted memory access looks like. It's the programming equivalent of learning Latin. It isn't required, but you will be better at pretty much everything you do involving modern English, Spanish, French, etc., as you will understand where things came from. It's even more useful though, as in the programming language world pretty much eve…

> It's even more useful though, as in the programming language world pretty much everything evolved out of C

Not really, there was a world of computing outside AT&T walls.

Lots of papers and computing manuals are available online for those that care about the actual history of computing.

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

#104
post #87

Earlier quoted context omitted.

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.

RISC-type architectures with a branch-and-link instruction (as opposed to a jsr- or call-type instruction) generally have a stack by convention only, because the CPU doesn't need one to operate. (For handling interrupts and exceptions there is usually some other mechanism for storing the old program counter.)

Can you point me to a RISC architecture that doesn't have push and pop instructions?

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

#105

What really made computers click to me was reading a book that had the premise: "learn just enough assembly to be able to implement C features by hand; we'll show you how". Sadly, I don't remember the title. Another revelation much later on, was, as discussed here, the realisation that C is indeed defined over an abstract machine. I think much of those realisations were because of reading about how crazy compiler opt…

Sounds a bit like "Programming from the Ground Up" [1].

[1] https://savannah.nongnu.org/projects/pgubook/

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

#106
post #63

I find this article to be disingenuous. Yes, C isnt "how a computer really works". Neither is assembly. 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). And thats really what people mean when they say C is closer to how a computer actually works: i…

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…

> We spend a lot of silicon forcing our computers to "work like C does" (the specification for how registers work may as well read "we need to run C code very quickly no matter how much register renaming costs us in silicon"

Can you elaborate? I thought I knew what register renaming was supposed to do, but I don't see the tight connection between register renaming and C.

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

#107
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?

Once you get used to it, it's not terrible. I don't debug on anything other than release builds (but with symbols) so that I know that I'm debugging the actual issues.

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

#108
post #61

What C teaches is that the underlying memory model is a flat, uniform, byte-addressed address space. One of the consequences of C is the extinguishing of machine architectures where the underlying memory model is not a flat, uniform, byte-addressed address space. Such as Symbolics or Burroughs architectures, or word-addressed machines.

We have our differences, but you’re totally correct here, and I’m not sure why you’re downvoted. The “byte addressable” thing is exactly why C was created over B, even, right? That was one of the crucial features not supported.

I don't think he is correct. The underlying representation of a pointer is not defined by the C standard. You could have a C implementation that works on segmented, non-flat architectures. Look at the C compilers from the DOS days, for example...

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

#109

Earlier quoted context omitted.

Why would you turn on optimization while debugging?

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

That'd be a compiler bug, then. I don't think those would be common.

EDIT: I suppose the other possibility is that the program is doing some weird things, like reading its own machine code from memory.

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

#110
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.

...like returning a pointer to the stack:

    char *dupstr(const char *src) {
       char new[1024];
       strlcpy(new, src, 1024);
       return new;
    }
Post reply on HN