Live data from Hacker News

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

words.steveklabnik.com

151–160 of 381 posts

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

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

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?

I can’t make a thorough argument, but u/flyinglizard (in a comment adjacent to mine) mentioned what I was thinking: Ruby/Python almost entirely abstracts the concept of pointers, references, and memory. For beginners and intermediates, it’s not a big deal until you get mutable data structures like lists and dicts. When I learned CS, we were taught C/C++ first, and I remember the concept of mutability and object identity being not at all difficult.

Without being able to refer to fundamental structures and concepts, I usually just exclusively teach students non-mutable patterns (e.g. list.sorted vs list.sort), while pushing them to become much proactive at inspecting and debugging.

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

#152
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…

But that's fighting against a straw man. When people advice others to "learn C," they don't mean the C99 specification they mean C as it is used in the real world. That includes pthreads, simd intrinsics, POSIX and a whole host of other features that aren't really C but what every decent C programmer uses daily.

As you point out, modern architectures are actually designed to run C efficiently, so I'd say that's a good argument in favor of learning C to learn how (modern) computers work. Pascal is at the same level as C, but no one says "learn Pascal to learn how computers work" because architectures weren't adapted according to that language.

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

#153

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’m convinced that Forth is a valuable intellectual exercise. Can you elaborate on how you feel Forth better matches how a computer actually works? I’m not yet convinced on that point, but I have no Forth experience.

The most fun, in a tinkering sense, that I've ever had with low level programming was in a variant of Forth (within Minecraft, years ago when the mod that included it was still up to date).

That experience made me regret that Forth wasn't part of my formal education experience: it is a wonderful slightly above assembly language.

Forth is what should be included in a BIOS as the absolute lowest level interpreted language. A basic machine abstraction could be made by using only interpreted functions/procedures and that could be used to bootstrap add-in routines for attached hardware. It would be very possible to write low level bootstrap drivers that could be used on any architecture providing the specification (including some interface hooks for defining how to register and use an IO interface).

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

#155

I like this article a lot. There are two ways you can think of looking at the field of programming: * As a continuum from "low level" to "high level". * As a giant bag of topics: strings, heap, hash tables, machine learning, garbage collection, function, instruction set, etc. If your goal is to have a broad understanding of CS, you want to explore the whole continuum and many topics. C is great for that because it ex…

Thank you! > if your goal is just to get familiar with that region of the continuum and not become an expert in a new language, C has a good price/performance ratio. I think this is a particularly great point in your post. I wonder what AndyKelley thinks of this, as in my understanding, that's sort of what Zig is trying to do as well. That is, Zig is attempting to be a language on a specific spot on the price/perform…

I think a new language has to be relatable with another and have some sort of huge defining feature(s) in order to get some sort of momentum, rust has rubyists(still one of my favorite languages)/c++ and safety, hopefully zig has something as well.

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

#156
post #68

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…

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…

> It's why things like Go work fine, because the stack isn't special. It's just memory.

Care to elaborate?

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

#158
This is a wrong statement on so many levels: "By learning C, you can learn how computers work". I am glad you did write an article but honestly you did not have to go to this length to explain your case. Anyone who says that learning C is a prereq. for understanding Computer architecture then my friend the advice is not coming from a right place. One reason I can think of is why author got confused is because a lot of freshman courses use C programming language in order to explain the computer architecture.

e.g. http://www.ece.utexas.edu/undergraduate/courses/306 use this textbook: https://www.amazon.com/Introduction-Computing-Systems-Gates-...

This course starts with assembly language and then use C as the first programming language in order to understand computer architecture. C is the de-facto language when it comes to teaching embedded systems (think limited HW resources like memory etc).

Learn Assembly to learn how computer works!

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

#159

Earlier quoted context omitted.

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.

You're the one that raised the metaphor, but okay?

I'm not saying that you can't do performance work without having done that. Just that you'll be at a disadvantage since you're at the mercy of whatever your HW vendor decides to disclose to you.

If you know this stuff you can work back from from first principals. With a high level memory architecture of a system(say tiled vs direct rendering GPU) you can reason about how certain operations will be fast and will be slow.

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

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

After recently (1 year) learning Rust I noticed that Rust teaches about low-level CS concepts of passing by value vs passing by pointer a lot better than C. Because you not just have references and values, but also have to think about richer semantics of what you are trying to do: sharing, mutability, and move semantics. So you learn not only that a few low level concepts exist, but you also learn how to use them correctly.
Post reply on HN