Live data from Hacker News

Why Learn to Program in C?

philipbuuck.com

21–30 of 123 posts

Re: Why Learn to Program in C?

#21
If anyone is interested in learning C as a first language, the lectures from Harvad's CS50 course make it more than feasible[0]. IMO the practical advantage of learning C first is that all other curly-brace languages become very easy to pick up.

[0] https://cs50.harvard.edu/lectures

Re: Why Learn to Program in C?

#22

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. No control over fragmentation. You have no control over the CPU's branch predictor or cache eviction policy.

You don't control the OS's thread scheduler, virtual memory implementation, etc.

Everyone picks a spot where things below that level are details they don't want to care about. You may have picked a slightly lower level, but there's nothing fundamentally different between you liking C and someone else liking Java (which is GC but not interpreted), Forth (interpreted but not GC), or Ruby (GC and interpreted).

People do serious work in Ruby for the same exact same reason you do serious work in C, it lets them control the things they need to control and ignore the things they don't.

Re: Why Learn to Program in C?

#24

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 do think C is a very useful programming language to learn. Certainly, concepts like memory and pointers can be crucial knowledge. But I disagree that C needs to be a programmer's first language. I've seen plenty of programmers who started out with Python or Java, then later went on to learn C and were none the worse. I myself started out with Visual Basic. Just because you didn't start out with C doesn't mean you can't subsequently learn it and low-level concepts.

Re: Why Learn to Program in C?

#25
post #2

I'm surprised that people have managed to get through a CS program without learning C (or, at least, C++)! It seems to me that programming should be taught simultaneously in Haskell (or Lisp?) and C. - C teaches you how computers work. - Haskell teaches you how programming logic works.

I'm of the mind we should be teaching predicate and temporal logic, formal methods, and critical thinking before teaching languages.

Though if you were to start with a language C might be a good one just to show you how sloppy thinking leads to incorrect behavior and poor performing programs.

Re: Why Learn to Program in C?

#26

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…

If you're going for a full-stack CS or CE degree, yes: start with a low-level near-bare-metal language and work up from there. One may need Java et al to initiate interest in such details, but once the path is started get down to basics ASAP and build up from there.

Re: Why Learn to Program in C?

#27
Ugh, while I 100% agree that learning C (or similar lower level language) should be a prereq for any programming job, the use of the K&R C book is idiomatic of what is wrong with C. To many people pick up that book and try to emulate what they read.

I firmly believe that book will teach you every bad habit you should never use in actual practice. 30 years ago, many of those "tricks" made sense given the compilers and computers of the time, but today your much better just writing straight clean C (for example using array indexes instead of pointers). Not only because its more maintainable, but because it often generates more efficient code due to hardware support for base+displacement addressing and compilers abilities to understand the intent and optimize the resulting code. Furthermore, code like what you find in that book is what has given C a bad name due to buffer overflows and the dozens of other things people think are the fault of "C" rather than the programming environment around it. Not the least of which is a formatting scheme that hides bugs.

So, PLEASE, if you are learning C, stay as far away from the K&R book as you can until you have gained enough proficiency to understand the pitfalls of may of the techniques taught in that book.

Re: Why Learn to Program in C?

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

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.

Re: Why Learn to Program in C?

#29

The whole handmade thing seems kind of silly. Yes, understanding what's beneath abstractions is important, but if you want to build software well, you should use your abstractions well, because not every piece of software needs lightning speed.

I don't think the author is arguing everyone should use c for everything. He is arguing that everyone should write something in c so that they understand the abstractions they use better. Abstraction is great because it let's you build your conceptual structure atop a virtual foundation, but your structure will be more grounded and therefore more sound if you learn to connect your understanding of the virtual foundation to its physical origins.

Re: Why Learn to Program in C?

#30

Ruby, Python, Perl, PHP, Java are all (mostly) built in C ( not to mention most databases ). Why not learn to program in C?

The same reason I didn't learn woodworking, even though my house is mostly made of wood.

I mean, look, I'm a professional C/C++ developer, and have been for 30 years. But the fact that your tools are written in it doesn't mean that you need to know it. (I need to know it because I work in embedded systems; C/C++ is the language of choice there, even now.)

Post reply on HN