Live data from Hacker News

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

words.steveklabnik.com

31–40 of 381 posts

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

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

I disagree with the bread analogy being on point.

For one, it misses the fact that learning how to bake it doesn't benefit the eating process. Whereas, learning how to code in C benefits (but is not required) in general programming.

I understand that analogies are always compromises because there is always going to be something that differs from the original motif. Also, analogies should be used when the motif is complicated with many layers of abstraction and using one adds something - whether it is clarity, succicicty or reduction of abstraction. In the case of parent comment, it is not too difficult to understand the original motif. So, the bread analogy adds virtually nothing to it.

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

#32
post #5

Earlier quoted context omitted.

> You're talking about strings here, right? This is not true in all languages, but certainly is for C :) It costs O(1) in memory to delimit strings with a null terminator and O(n) in time to execute strnlen(), right? It's not free. Though, if you're lucky your string is in rodata and the compiler can calculate the sizeof() in advance, this is very-nearly-free. EDIT: misunderstanding, disregard

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

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

#33
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".

In some contexts these mean the same thing (a layer of abstraction), while in other, more technical, they mean different things.

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

#34
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 works: there are many kinds of different computers, with different architectures

As with many things, this phrase is an approximation. C is a portable implementation of many useful behaviors which map reasonably closely to tasks commonly done on most instruction sets. C programmers rarely write assembly to optimize (usually to capture those arch-specific features which are unrepresentable in C), but programmers in other languages often reach for C to write the high-performance parts of their code. The same reason C programmers in the early days would reach for assembly is now the reason higher-level programmers reach for C.

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

#35
post #24

Earlier quoted context omitted.

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

Or LLVM, the Low Level Virtual Machine?

... which now just LLVM, because it's so confusing! http://lists.llvm.org/pipermail/llvm-dev/2011-December/04644...

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

#38
post #19

Learning C has practical benefits, but gaining an understanding of how computers work is not one of them. Learning an assembler would be more helpful in this regard, but in my opinion one might want to start with a very well-written article by Mark Smotherman: https://people.cs.clemson.edu/~mark/uprog.html If you want to see how a CPU works, I highly recommend visiting http://www.visual6502.org/

While I wouldn't suggest anyone learn C for the explicit purpose of learning how computers work, being familiar with pointers and memory allocation can go a long way.

Novice unity programmers struggle to understand why using classes (reference type in c#) in a game loop causes performance issues, but structs (value type in c#) are not as costly. For someone who has called malloc before, this isn't too hard to grasp, but before someone who sticks to garbage collected languages, it seems bizarre and arbitrary.

Of course memory allocation is an OS function, so this isn't "understanding the hardware," but it is a much deeper understanding of computers than not knowing what happens when you create an object.

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

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

Learning to read Ancient Greek should be on that list.

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

#40
I think that in order have true mastery of C, one must understand why certain things are undefined. For example signed integer overflow is undefined. Why? Well different architectures handle overflow in their own ways (saturating vs modulo arithmetic, twos compliment). C can a great way to learn about computers in general vs assembly on a specific architecture--unless you approach C undefined behavior as most undergrads do and proclaim how arbitrary the silly C language spec is.
Post reply on HN