Live data from Hacker News

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

words.steveklabnik.com

1–10 of 381 posts

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

#3

C... IDK. Maybe. But, pointers yes definitely. Even some assembly. You really should understand how things like .size or lengh() aren’t “free” and how they work.

Funny enough, pointers are a great example of an abstraction provided by C that people assume is isomorphic to hardware, when they don't: https://blog.regehr.org/archives/1621

That said, I 10000% agree that pointers are a thing that is great to learn.

> You really should understand how things like .size or lengh() aren’t “free” and how they work.

You're talking about strings here, right? This is not true in all languages, but certainly is true that these are not free in C :)

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

#4
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 optimizations can be and how UB can _actually_ do anything.

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

#5

C... IDK. Maybe. But, pointers yes definitely. Even some assembly. You really should understand how things like .size or lengh() aren’t “free” and how they work.

Funny enough, pointers are a great example of an abstraction provided by C that people assume is isomorphic to hardware, when they don't: https://blog.regehr.org/archives/1621 That said, I 10000% agree that pointers are a thing that is great to learn. > You really should understand how things like .size or lengh() aren’t “free” and how they work. You're talking about strings here, right? This is not true in all langu…

> 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

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

#6
I don't know if I'm in the should camp but beneficial? Yes, since so many things in programming might be taken for granted without seeing how things are done another level down. But then you could keep going all the way down, so who decides how far a student should go?

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

#7

C... IDK. Maybe. But, pointers yes definitely. Even some assembly. You really should understand how things like .size or lengh() aren’t “free” and how they work.

Funny enough, pointers are a great example of an abstraction provided by C that people assume is isomorphic to hardware, when they don't: https://blog.regehr.org/archives/1621 That said, I 10000% agree that pointers are a thing that is great to learn. > You really should understand how things like .size or lengh() aren’t “free” and how they work. You're talking about strings here, right? This is not true in all langu…

[deleted]

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

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

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

#9
post #5

Earlier quoted context omitted.

Funny enough, pointers are a great example of an abstraction provided by C that people assume is isomorphic to hardware, when they don't: https://blog.regehr.org/archives/1621 That said, I 10000% agree that pointers are a thing that is great to learn. > You really should understand how things like .size or lengh() aren’t “free” and how they work. You're talking about strings here, right? This is not true in all langu…

> 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

Only if your strings are null terminated; many languages do not use null termination for various reasons, and that's one of them. "Pascal strings" being the nickname, given how old this idea is, and given it was a direct competitor to C at the time.

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

#10
post #5

Earlier quoted context omitted.

Funny enough, pointers are a great example of an abstraction provided by C that people assume is isomorphic to hardware, when they don't: https://blog.regehr.org/archives/1621 That said, I 10000% agree that pointers are a thing that is great to learn. > You really should understand how things like .size or lengh() aren’t “free” and how they work. You're talking about strings here, right? This is not true in all langu…

> 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

Right. But some languages prefix the string data with its length and omit the null terminator. So, depending on if the struct is passed in registers, you could say .length is free, in that it wouldn't even need a load.
Post reply on HN