Live data from Hacker News

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

words.steveklabnik.com

41–50 of 381 posts

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

#41
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: its a language with fewer abstractions than many others (most notably, its lack of garbage collection, object oriented behaviors, and a small runtime). That lack of abstraction means that you have to implement those concepts if you want to use them which will give you an understanding of how those abstractions work in the language that has them built in.

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

#42
If you want to learn how it works, it's a lot better to start at the lower level in my opinion. Reverse engineer something you use every day, get an achievable goal, maybe fire up x64dbg, go out and find some malware, make an advanced cheat for your favorite game or crack something.

You'll learn what code looks like to the CPU, you'll get a feeling for how OOP works inside that box (things like the "this" pointer, vtables), what structures look like in memory, how dynamic linking works vs static linking by actually looking at what that code looks like in an executable. And you'll have something to show for it - something to prove you've acquired enough knowledge to achieve goals.

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

#43
post #8

Do you need to learn C to have a successful career in CS or any other field? No. Should you learn it? Yes. Do you need to bake bread to eat it? No. Should you learn to bake it? Yes. There are lots of things you should learn to do because they're useful and teach you about how the world works. The miracle of society is that you don't have to learn most of them to enjoy using them.

That bread analogy is on point. The old quote comes to mind, >A human being should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give orders, cooperate, act alone, solve equations, analyse a new problem, pitch manure, program a computer, cook a tasty meal, fight efficiently, die g…

Worth noting that Heinlein didn't necessarily actually believe this himself. It's spoken by one of the many classic polymath characters which he liked to include in his stories.

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

#44

Earlier quoted context omitted.

That assumes that all strings are C strings which isn't true. For example, Pascal-style strings have a size before the string data, and Rust and C++ strings have the size as metadata on stack and the string data in heap.

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.)

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

#45

Earlier quoted context omitted.

IIRC there was some UB feature that when compiled with GCC would launch nethack.

Found it: >When GCC identified “bad” C++ code, it tried to start NetHack, Rogue, or Towers of Hanoi. Failing all three, it would just print out a nice, cryptic error message. https://feross.org/gcc-ownage/

Alright, that is pretty awesome.

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

#46
post #15

Coming from an operating system background, I find the article's use of "virtual machine" very bizarre. The article confuses very different things by stating that "'runtime', 'virtual machine' and 'abstract machine' are different words for the same fundamental thing".

"Virtual machine" has a broader sense than emulation or virtualization within a hypervisor. From the perspective of an assembly programmer, C implements a low level virtual machine that abstracts much of the drudgery that assembly requires. For instance, you can store 32 signed bits in a variable without caring about the native word size and bit representation in the underlying hardware (though in some circumstances you may still care). That is the "virtual" part of C's abstraction.

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

#47
Discussing this with other tech folk in my circle of a certain age, I'm actually in favor of learning BASIC (old-school line-number basic) to learn how a computer works, because the conceptual model is not dissimilar to assembly language.

Concepts of structured programming arise from noting patterns commonly used -- you start using GOSUB instead of GOTO; you tend to make your loops very strictly nested because otherwise the code becomes unmaintainable, you find yourself writing data structures to manage related records, etc. From there, the transition to structured programming becomes very natural -- just formalizing some concepts that you've already internalized.

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

#49
post #24
post #15

Coming from an operating system background, I find the article's use of "virtual machine" very bizarre. The article confuses very different things by stating that "'runtime', 'virtual machine' and 'abstract machine' are different words for the same fundamental thing".

How do you feel about the "Java Virtual Machine" then?

A java virtual machine runs java byte code. It makes sense because the compiler emits code for a machine that is an abstract concept, not something that physically exists, and the virtual machine executes this bytecode.

In typical use of a C compiler, you get code for the target processor, i.e. x86. In theory, you don't have to worry about the underlying hardware, so you could say you are programming for some abstract machine that runs C code, but it is much less meaningful than saying java has a virtual machine.

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

#50

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 subset of x86 instructions into the opcodes for that toy CPU, then a limited dialect of C that generated that assembly code, that we converted to opcodes, that we ran on that simulated toy CPU.

It was probably the hardest course of my entire degree, and I ended up taking it twice, but at the end of the second go-round, computers were no longer a magic black box.

Post reply on HN