Live data from Hacker News

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

words.steveklabnik.com

141–150 of 381 posts

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

#141
post #58

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…

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

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

Go does that too. C teaches manual memory allocation, de-allocation and pointer arithmetic as well.

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

#142

One of my favorite classes in college was Computer Architecture 1 and 2, which encompassed logic gates, Boolean logic, and progressed to assembly language usage. C was covered in other classes and was a natural next step from Architecture. I credit those classes a ton for my lower level knowledge.

I agree 100%, that was far and away the most valuable single class I took in college. We used the Tannenbaum book and a digital logic simulator, and worked up from basic gates into basic components (e.g. flip-flops and muxes, etc), then combined those into bigger components (ALU, registers, SRAM, etc), combined those into a toy 8-bit CPU, implemented cache and main memory, wrote an assembler that converted a small su…

>It was probably the hardest course of my entire degree, and I ended up taking it twice,

Interesting. Did you study at a US univ.? I have not heard of being able to take the same course twice (except via, say, failing a year of the degree and having to repeat the whole year). I did hear that US universities are more flexible in some ways than, say, Indian ones, whose rules are probably based on British ones (maybe ones from much before); e.g. being able to mix and match courses, take longer than the standard 4 years for a degree, etc. I have American friends and relatives who told me that. But didn't know one could repeat a course. Seems like a useful feature.

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

#143
post #75
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.

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.

I suggest maybe you learn C :) or Rust.

There are significant performance and strategy differences between the stack and the heap. On the stack, allocation is cheap, deallocation is free and automatic, fragmentation is impossible, the resource is limited, and the lifetime is lexically scoped.

On the heap, allocation might be cheap or it might be expensive, deallocation might be cheap or it might be expensive, fragmentation is a risk, the resource is 'unlimited', and the lifetime is unscoped.

Your statement is equivalent to saying "there's no difference between pointers and integers" - technically, they are both just numbers that live in registers or somewhere in memory. In reality, that approach will not get you far in computer science.

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

#145
This is an excellent essay, and touches on a lot of the key ideas both of what C is and of how C maps to the hardware. In particular, I completely agree with where Steve lands here, which is that C can give you more understanding of how computers work but won't necessarily reveal some "deep ultimate truth" about the zen of computers. Especially in light of this essay recently shared on HN (https://blog.erratasec.com/2015/03/x86-is-high-level-languag...), which makes the excellent point that even a language that is compiling down to raw x86 assembly is still operating in a "virtual machine" relative to what goes on in the actual chip and the flow of electrons through the silicon-metal substrate.

It's abstractions all the way down.

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

#146

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…

Thank you for this =)

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

#147

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…

It varies from application to application.

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

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

#148

Earlier quoted context omitted.

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.

They don't solve problems created by C, they just solve problems C doesn't. The problems still exist, and sometimes the high-level compiler even picks the wrong solution. Learning C helps you understand when and why this has happened.

Arguably those problems did not exist before the C-era as software wasn't large or complicated enough. C++ directly attempts to improve over C by providing new mechanisms to solve problems encountered by C developers every day.

Point is that out of context, a lot of the things modern languages provide seem superfluous. Why have objects? Why have templates, closures, or lambdas? For a novice programmer, these are many answers for questions yet to be asked.

When you come from a heavy C background and you encounter something like templates, you know EXACTLY what this is for and wish you had it years ago.

I'm as hardcore as they get C programmer and I'm having a ball with C# for this very reason.

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

#149

Earlier quoted context omitted.

Sounds a bit like "Programming from the Ground Up" [1]. [1] https://savannah.nongnu.org/projects/pgubook/

Or maybe just Professional Assembly Language [1] [1] http://www.wrox.com/WileyCDA/WroxTitle/Professional-Assembly...

Will check this out as well as the book above. Thank you.

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

#150

"In 1972, on a PDP-11, they wrote the first C compiler, and simultaneously re-wrote UNIX in C. Initially, portability wasn’t the actual goal, but C did resonate with a lot of people, and C compilers were ported to other systems." The fathers of UNIX explicitly said in one of the interviews that they invented C so that they could make UNIX portable.

So, I had heard that as well, but http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.138..., co-authored by Dennis Ritchie, says

> C was developed for the PDP-11 on the UNIX system in 1972. Portability was not an explicit goal in its design, even though limitations in the underlying machine model assumed by the predecessors of C made us well aware that not all machines were the same [2].

So that's what I went with.

Post reply on HN