The C programming langauge

  • #1
ergospherical
883
1,213
My dad gave me his old copy of "the c programming language" by Kernighan and Ritchie, but I was flicking through it and it comes across as quite old-fashioned and has a lot of random sh*t like pointer arithmetic, memory allocation etc.

Being an idiot, and one who's pretty out of practice with any of this stuff for a few years, is it worth trying to learn from it? I have the gut feeling that you can't really learn compsci from books, and it's a better use of time to just try and bang out some of the exercises on Project Euler or something.
 

Answers and Replies

  • #3
sysprog
2,613
1,783
My dad gave me his old copy of "the c programming language" by Kernighan and Ritchie, but I was flicking through it and it comes across as quite old-fashioned and has a lot of random sh*t like pointer arithmetic, memory allocation etc.

Being an idiot, and one who's pretty out of practice with any of this stuff for a few years, is it worth trying to learn from it? I have the gut feeling that you can't really learn compsci from books, and it's a better use of time to just try and bang out some of the exercises on Project Euler or something.
What the hecK? Pointer arithmetic is not random stuff. That's a good book. I suggest that you not only work some of the excercises; Please go ahead and write some code. "Can you code?" is something that one of my bosses said was the main thing that he cared about in a prospective employee.
 
  • #4
ergospherical
883
1,213
nah my issue with it is that it’s a) old and b) I don’t really care about the subtleties of computer architecture at this stage

but I don’t know how far I can get just winging it, without ever eventually sitting down to learn the nitty-gritty stuff, if you catch my drift
 
  • #5
berkeman
Mentor
64,195
15,448
Is it the 2nd Edition? It is *much* better than the 1st Edition, IMO.

Yes, pointers are very important to learn, and so are data structures. K&R 2nd Edition is all that I use for my C programming. (I've had separate classes in data structures, compilers, etc. back in university)
 
  • #6
sysprog
2,613
1,783
nah my issue with it is that it’s a) old and b) I don’t really care about the subtleties of computer architecture at this stage

but I don’t know how far I can get just winging it, without ever eventually sitting down to learn the nitty-gritty stuff, if you catch my drift
Wow. Just wow. I think that regarding the "subtleties" and the "nitty gritty stuff" ##-## that's 'where it's at' ##-## please read, for example, some of @pbuk's and @Mark44's and @Baluncore's and @jbriggs444's and @berkeman's and other techie persons' posts here on PF ##\dots##
 
  • #7
36,716
8,717
I have the gut feeling that you can't really learn compsci from books
That's a little like saying, "You can't really learn physics/chemistry/whatever from books." The only difference I can see between these disciplines and programming is that you get immediate feedback when you're programming, possibly in the form of compiler errors or weird results.

I don't think you'll get very far by "banging out" exercises from Project Euler.
but I don’t know how far I can get just winging it, without ever eventually sitting down to learn the nitty-gritty stuff, if you catch my drift
Without understanding the "nitty-gritty stuff," like pointers and addresses, arrays, and memory allocation, you really won't get very far.
 
  • Like
Likes symbolipoint and sysprog
  • #8
36,716
8,717
Is it the 2nd Edition? It is *much* better than the 1st Edition, IMO.
I have both. I agree that 2nd Ed. is better.
 
  • #9
Baluncore
Science Advisor
12,096
6,208
I seem to remember the original version of K&R explained how to write C, but not what it would do if you did.
A few years later a new programmer trained in C, told me that FORTRAN was useless because you couldn't declare a pointer. I had to point out that in FORTRAN everything was a pointer.
 
  • Like
Likes nsaspook, sysprog and pbuk
  • #10
Vanadium 50
Staff Emeritus
Science Advisor
Education Advisor
29,634
15,138
it’s old
No older than Jackson. Does that make Jackson a bad book?

and has a lot of random **** like pointer arithmetic
If you think pointer arithmetic is "random stuff" then the book is too advanced for you.
 
  • Like
  • Haha
Likes vanhees71, sysprog, jim mcnamara and 1 other person
  • #12
pbuk
Science Advisor
Homework Helper
Gold Member
4,049
2,380
nah my issue with it is that it’s a) old and b) I don’t really care about the subtleties of computer architecture at this stage

but I don’t know how far I can get just winging it, without ever eventually sitting down to learn the nitty-gritty stuff, if you catch my drift
On Nat Sci you can go all the way just winging it. If you are interested in a rigoruous background to Comp Sci then K&R is a great work of historical importance and interest. But it's 2021 and you need to focus: why do you want to learn C?

Edit: there are 59 courses here on scientific computing, not a lot of them have any C as a prerequisite: https://www.training.cam.ac.uk/ucs/theme/scientific-comp?providerId=36407
 
  • Like
Likes vanhees71, symbolipoint, sysprog and 1 other person
  • #13
ergospherical
883
1,213
On Nat Sci you can go all the way just winging it. If you are interested in a rigoruous background to Comp Sci then K&R is a great work of historical importance and interest. But it's 2021 and you need to focus: why do you want to learn C?

The main reason I'm trying to get some practice now is that I want to join the hackathon society next yearr, and I don't particularly want to learn C (although I've done some objective-c for iOS, which is a bit different... hehe), since I think I'm mainly going to use python from here on.

What should I be doing to practice? It's fun just messing around with it, but I don't want to get into the habit of writing complete spaghetti code haha
 
  • #14
pbuk
Science Advisor
Homework Helper
Gold Member
4,049
2,380
Yes objective-c is a 'bit' different :biggrin:.

The first 100 problems in project Euler are an OK way of practicing a language, although you can solve them just as well with ugly code as with good code. After that it is more about knowing a number theory trick than good coding.

Only a few days till the start of term, can you wait to meet up with current members to work on some stuff together/in competition?
 
  • Like
Likes vanhees71 and ergospherical
  • #15
Dragon27
106
77
C is probably the lowest of all "high-level" programming languages, just one step above Assembly. Memory allocation and all this other "random stuff" is the whole point of programming in C, that's why people choose it to write device drivers, operating systems (or at least their kernels), embedded software, and other stuff like that.
 
  • Like
Likes berkeman, sysprog and vanhees71
  • #16
kith
Science Advisor
1,415
505
Most programming languages use many different abstractions, lots of encapsulated black box functionality and a huge standard library. The C standard, on the other hand, defines a very clear and simple programming model with a tiny standard library. This model is also very close to the metal. It allows for a deep understanding of programming based on fundamental building blocks. C is beautiful and K&R is the book which makes this beauty tangible.

A completely different kettle of fish is the question of whether C is the right language to do a project you have on your mind (it probably isn't).
 
  • Like
Likes vanhees71, berkeman, sysprog and 1 other person
  • #17
Hornbein
1,125
829
Low level languages are written in the bare instructions to the CPU. So if you want to know what the computer is actually doing then that's what you need to know. The trouble with that is that low level languages are verbose and error prone, and any program written in that language works only on that CPU. It's not portable.

All operating systems were written in assembly language. That meant whenever you came up with a new computer you had to write the operating system more or less from zero. Bummer. So K&R came up with C and used it to write the UNIX operating system. It's basically a replacement for assembly language. It's much easier to port UNIX to your system than to start with nothing. So C is a sort of medium level language. It's good for writing programs that operate machines.

If you don't care about operating systems or machines or what the CPU is doing then you can go with a higher level language like C++ or Python or whatever. The emphasis of C++ is more on writing modular programs that are error-free and less on something that executes at the highest possible speed. Python is more flexible -- not that that is always a good thing -- and slower. And so forth and so on.

If you want to write quick programs then it is necessary to know exactly what the computer is doing and how much time each operation takes. If you don't care about that then you don't care about that.
 

Suggested for: The C programming langauge

  • Last Post
Replies
3
Views
893
Replies
1
Views
416
  • Last Post
Replies
21
Views
7K
Replies
1
Views
869
  • Last Post
Replies
1
Views
681
Replies
1
Views
651
Replies
1
Views
44
  • Last Post
Replies
14
Views
4K
Replies
7
Views
2K
Top