Live data from Hacker News

Why Learn to Program in C?

philipbuuck.com

31–40 of 123 posts

Re: Why Learn to Program in C?

#31

Until not too long ago, De Anza College still taught C as an introductory programming language (I think because some recently retired instructors wrote a textbook on it). Even now, from what I've seen of the syllabi online, their C++ course that replaced it is still mostly C with some sprinkling of classes added on. I thought it was a horrible idea, and I had a pretty miserable experience at De Anza. If you're just s…

My experience is the reverse. I think that beginning with C gives you the necessary knowledge of the inner workings of programs and systems that is required if you want to end up with a degree in CS/CE/similar. I've seen too many programmers that started with Java or Python and then didn't know what exactly is memory, what is "allocation" or similar concepts that are required if you want to understand what's going on…

I agree. Furthermore, I think pointers in C is a simple concept that becomes incredibly powerful, and also gives a lot of insight into how memory works and the different data structures.

Re: Why Learn to Program in C?

#32
post #3

I am a strong believer in learning C as your first language. Why? Well a number of reasons but the two main ones are 1) it teaches you about what is happening at a lower level so you have some idea about what is happening behind the scenes of that Java code you wrote or whatever and 2) it makes you appreciate just how lucky you have it in higher level languages. However I don't think you should start writing all your…

> although I would if you needed a fast, native library to call from your webapp

Honestly, at this point you're probably better of using Rust for that.

Re: Why Learn to Program in C?

#33

I find it odd that anyone would question the value of learning C. I find the negative attitudes toward C to be very odd in general. Now, it is clear to me that I am in the minority, but I can't understand why people would be doing serious work in an interpreted language. I detest garbage collection as I have no control over it. I am sure I could write statements like this all day. Don't get me wrong: I use perl when…

> I can't understand why people would be doing serious work in an interpreted language. I detest garbage collection as I have no control over it. You have no control over C's register allocator. (Well, very little, `register` doesn't mean much.) Assuming you use it, you have no control over how the standard library's malloc() and free() work. malloc() could be best-fit, first-fit, something else entirely, who knows.…

Exactly. If I don't need to care about X, picking a language where I don't have to care about X is a win (for any value of X).

That is, it's a win right up until the scope or scale grows to the point that I now have to care about X. Then the language where I "don't have to" usually turns into a language where I can't, and I'm trapped.

Re: Why Learn to Program in C?

#34

I find it odd that anyone would question the value of learning C. I find the negative attitudes toward C to be very odd in general. Now, it is clear to me that I am in the minority, but I can't understand why people would be doing serious work in an interpreted language. I detest garbage collection as I have no control over it. I am sure I could write statements like this all day. Don't get me wrong: I use perl when…

> I can't understand why people would be doing serious work in an interpreted language. I detest garbage collection as I have no control over it. You have no control over C's register allocator. (Well, very little, `register` doesn't mean much.) Assuming you use it, you have no control over how the standard library's malloc() and free() work. malloc() could be best-fit, first-fit, something else entirely, who knows.…

Yes, but interpreted is slow, and garbage collection causes pauses at essentially random times. These things are fine for one off sorts of problems where it doesn't matter much if it takes a little longer. If you are writing an application that is meant to be run thousands or millions of times, I start to wonder why people don't care more about these trade-offs (the answer is, of course, they do . . . if they are, for example, running large infrastructure like Google or Amazon).

My point isn't/wasn't so much to crap on other languages, but to express dismay at why people crap on C so much or view it as irrelevant. Ruby is definitely not irrelevant. Why would people think C is?

Re: Why Learn to Program in C?

#35

C is great. I wouldn't recommend starting programming in C, though. At least not with the standard exercises you see. Get user input, read a file, do this do that with it. Why? the C standard library is full of gotchas and tricks and goofy shit that makes it unsuitable for new programmers. The comp.lang.c FAQ should be standard reading material for anyone taking a C class. Look at all the posts on StackOverflow about…

My first language was C and I loved it. Maybe it takes a certain type of mindset and tenaciousness (madness?) that will put up with the gotchas. It was exactly those gotchas that got me hooked though. It was similar gotchas that made me love Linux the terminal, vi etc ...

The argument that one "should study other languages before they're fit to learn C" is terrible IMO and somewhat condescending. It's like saying one must learn "nedit/pico" before starting with editors like "emacs/vi". Please stop repeating that - especially if you have not done much C.

I am probably too old to understand the constant hate and criticism on why C shouldn't be taught to beginners. Not everything "has to be easy". Starting with C & Linux, I always had an advantage later in my career because it was these skills that enabled me to drill deeper than those who didn't know C & system programming.

C isn't just hard for beginners because of the language but the rest of the tool-chain. If you can get over this then learning C will also teach how to debug with gdb, strace, valgrind and learning about low level system calls, and a great deal about how a program can be loaded/structured e.g.: dynamic & static linking. Also where the resources are used and how to eliminate it’s bottlenecks. What is a heap, stack or static memory? How does memory management or garbage-collection work on a modern OS? What is IPC and how do the individual system calls function & require as input? How do you compile a program and optimize it for different target platforms? How do you write Makefiles or use autotools etc ...

Tell me again which other language forces you to learn these things? You could easily build a career just on C & Linux because of this "additional learning curve" and extra knowledge that a good C developer will have.

Sorry for all my bias (as I said my views might be very outdated :-))

Re: Why Learn to Program in C?

#36

C is great. I wouldn't recommend starting programming in C, though. At least not with the standard exercises you see. Get user input, read a file, do this do that with it. Why? the C standard library is full of gotchas and tricks and goofy shit that makes it unsuitable for new programmers. The comp.lang.c FAQ should be standard reading material for anyone taking a C class. Look at all the posts on StackOverflow about…

I started with C and it took me 3 good years fooling around with other languages too to get a "good" understanding of C. Better learn with higher level languages indeed...

Re: Why Learn to Program in C?

#37
post #20

Earlier quoted context omitted.

Overcoming goofy shit and gotchas is part of any programming system.

Yeah, but why start with an exceedingly painful one except to needlessly inflict pain and suffering on students. Better to lay the groundwork with a friendlier language, learn the basics, and then move on to the more complicated gottchas (at least in my amateur opinion).

JavaScript has been touted as an intro language, and in some ways it's even quirkier than C.

Re: Why Learn to Program in C?

#38
While I agree with the premise that it is important to know C, I also agree with many of the comments here suggesting that there are other better first languages out there. As a recent college grad ('15), my intro course was in Python and then the next course was in C. Python was easy to jump into--it usually just made sense and worked. While learning about loops, lists, strings, etc, that was useful. Equally useful was then moving to C and getting a better understanding of the "lower level" (especially in the sophomore computer systems course). But you don't have to understand caches, page tables, and threading to jump into a first programming class and master the principles.

Re: Why Learn to Program in C?

#39

Until not too long ago, De Anza College still taught C as an introductory programming language (I think because some recently retired instructors wrote a textbook on it). Even now, from what I've seen of the syllabi online, their C++ course that replaced it is still mostly C with some sprinkling of classes added on. I thought it was a horrible idea, and I had a pretty miserable experience at De Anza. If you're just s…

> not get bogged down in pointer hell

No one should get bogged down in pointer hell. I program C for real work all the time, and I teach it to undergrads, and we use pointers carefully and with awareness. We don't do arithmetic or other 'clever' stuff. And we don't get bogged down in pointer hell.

Why do we teach it to undergrads? Among other reasons, because trying to teach OS or compilers to students who don't get pointers or any other low-level stuff is miserable.

Re: Why Learn to Program in C?

#40
post #28
post #20

Earlier quoted context omitted.

Yeah, but why start with an exceedingly painful one except to needlessly inflict pain and suffering on students. Better to lay the groundwork with a friendlier language, learn the basics, and then move on to the more complicated gottchas (at least in my amateur opinion).

What language would you suggest is friendlier, and less rife with gotchas? I find the rules of C fairly reasonable, at least on the surface.

#include int main(void) { (printf)("C is awesome\n"); return 0; }
Post reply on HN