Monday, November 27, 2006

Should All Programmers Learn C? I don't think so.

This list looks like it has been written by a 12 year old.

To say *every* programmer should learn C is complete idiocy. I can't think of a single reason why *every* programmer should learn C in 2006. In fact the only reason I can think of to use C would be for Device Drivers. I know probably 200 developers. How many write device drivers - none.

Even things like Micro-controllers have embedded JVM's these days.

A counter argument would be that things like JVM's, databases, Operating Systems are written in C. This may be true, but again how many people actually write these? Maybe 5-10% of all programmers.

Oh hold on. Games. They are predominately written in C++. Some could argue that is C, although comparing C++ with C is like comparing C# with C. Sure they may *look* the same but they are about as similar as a Daewoo and a Ferrari.

Anyway here is the list with my rebuttals:

1) C is lower level then other programming languages (C++, Java). Programming at a lower level allows you to further your understanding of computers, as a whole.

Bit of a hoary old chestnut that one. Sure you have to allocate/deallocate your own memory, and string handling is a bit ugly but other than pointers (and C++ has those too) C is not really that different.

2) Device drivers and operating systems are written exclusively in C. Now, you may never write a device driver or an operating system, but what if you are ever required to modify one?

That is completely false I'm afraid. Device drivers are written in C++ these days (remember C++ is no closer to C than C#). There is an OS (singularity) with the Kernel, OS and device drivers all written in C#. I have to concede that some parts are written in C.

3) What if you ever want to get a job programming microcontrollers? They are programmed in C. Are you going to limit your possible list of jobs because you didn't want to learn a new language?

Again a lot of microcontrollers are Java based so this argument falls down. The other part to the argument is non nonsensical. Just because you know C, doesn't mean you know anything about microcontrollers. Also I don't know how to fly a plane either. Am I limiting my possible list of jobs?

4) C programs are smaller and faster then any other program created in a different language. Sometimes your program needs that speed boost that only C can give it.

A complete fallacy. A program is as fast as its bottleneck and in most circumstances this is the person in front of the keyboard. Also this argument is like saying an Indy car can go 400km/h and an F1 car can only go 360km/h. Therefore an Indy car is faster....

5) If you have learned C, you can learn any modern programming language. The reason behind this is that all modern programming languages are based on C (Java, C++, C#, etc).

Most modern languages are far more than the syntax. .NET and Java have huge frameworks you need to learn that have nothing to do with the fact the a for loop looks the same in C, Java and C#

6) Because C has been around for many years, it has a large community and collective code base. This allows you to quickly and efficiently implement new algorithms or functions that have been programmed before.

Um have you not heard of google? I can't remember the last time I couldn't find a solution to a particular programming problem I have had. I program using C#, Delphi and C++

7) C is the language of the Open Source community. The Open Source poster child, Linux, was coded in C. If you know C, you can participate in and contribute to numerous Open Source communities like Source Forge.

Can't argue with that. Also the poster couldn't argue with the fact that there are just as many Java, or C# or Delphi open source projects

8) C is the only language that teaches you what pointers really are. C# and Java skip the subject completely. It is pointers that give C its power.

And it's pointers that give C it's largest problem. I'd rather let Gurus write a compiler or Framework for me that takes away the need to worry about the nuts and bolts, and lets me get on with writing the application.

9) C is still the most commonly required language for programming jobs. It is well worth your time to get C under your belt.

Well this is arguable too. There is estimated to be more COBOL code in the world. Does that mean we should all learn COBOL too?

10) Anything that has a microprocessor in it has support for C. From your microwave to your cell phone, C powers technology.

Yip and there are usually other options too. I can program my Cellphone in Visual Basic if I want to....

Dont get me wrong. In certain circumstances C is the best fit, and I cut my teeth in the late 80's with C. But to say that every programmer should learn it is a little overstating things IMHO.

16 comments:

Daniel said...

thanks for writing this, I totally agree with you. That's what I thought earlier when the list was dugg

diogo said...

i agree with you on *most* (99%). you indeed refutes each and every one of his claims. the only thing i think its worth saying, is that indeed C is a language that should be on the belt of any *good* programmer. If you're concerned with making your code work, getting your money the end of the month, no, maybe you shouldnt learn C. C, however, is one of the most important programming languages ever (for bad or worse). If you take the craft of programming seriously, you should learn it, even if you never code on it professionaly.

On that same line tho', you should also learn a couple other languages (such as one off the LISP family). each of these languages teaches you smth, and it will, eventually, make you a better programmer.

My point is, yes, you should learn C. No, not one of the claims the other guy did was valuable. Basically, you should learn it, because everything you see now has some sort of familiarity with C. The exception beign functional programming, the logic paradigm, and such...but if you know that, you probably know C already :D

Peter Cooper said...

The irony of calling someone who wrote a reasonable, though lightweight, post an 'idiot' in a post that reads like a bitchy diatribe is great.

Whether or not 'every' programmer should learn C is like asking.. should everyone learn about history? There are some people who say no, but anyone with an ounce of sense will study history to some degree. C is a living history of programming, and one that still has much utility. Understanding the problems that programming in C raises will produce a better programmer whatever final language they end up using.

Bruko said...

First of all, the previous guy's list doesn't look like it was written by a 12-year-old; however, the assertion that the previous guy's claims were "complete idiocy", and that the guys is an "idiot" in general, is pretty immature.

Secondly, I wouldn't make the claim that C++ is to C what a Ferrari is to a Daewoo. Maybe what a Ferrari is to a 350Z. Most programmers I know use a kind of dialect which incorporates much idiomatic C into their C++ code, rather than programming in a "pure" C++. The differences typically come as much from standard library usage as they do from using C++'s OOP features.

Thirdly: An Indy car goes 400km/h whereas the F1 goes 360km/h. So, yes, the Indy car *is*, in fact, faster. Period. The idea that performance bottlenecks come predominantly from the guy behind the keyboard is, in many cases true. But in good shops with competent programmers or better, this is also many times not the case. Sometimes pure performance is an issue.

Finally, pointers do matter. They matter because they play a role in understanding referencing, garbage collection and other computational issues, and understanding them is a worthwhile pursuit. Yes, they can be a problem, but so can virulent retorts to posts.

Dude, relax. I agree that the other list was, purely speaking, not strictly correct, but I don't disagree with the spirit of it, that programmers should learn as much about their hardware as they can. Is the guy wrong? It depends on what you want to do. But is he an "idiot"? No, he's not. Try not to be one yourself.

James said...

Bruko: I think you misread what I was saying in a couple of points. I wasn't calling C the Daewoo and C++ the Ferrari. I was pointing out the differences. Both look the same on the outside - four wheels, general shape, windscreen etc, but are very different and have a very different purpose.

My point with the Indy Car vs the F1 car is the an Indy Car does indeed have a faster top speed, but going around a track with actual corners, the F1 car would be much much faster because of it's greater braking and cornering ability. I.E just because one aspect of something is fast, doesn't make it the fastest in all conditions.

James said...

UPDATE: I have changed the heading. I agree that it wasn't completely fair.

jk3000 said...

What's wrong with learning C? You don't need to learn it, but it doesn't take long to learn, and there's always a lot of utility in knowing it because it's popular. It's like, if you're on Unix, you should learn at least a little shell scripting and maybe some Perl. If you're on Windows, you should learn a little VB or C#. If you're on the Mac, it's useful to learn ObjC. If you use GNU emacs, you should try to learn some Lisp. All these systems were written in C, and it's good to learn for that reason, to get some insight into your environment. It's also very useful to know when you need to write ad-hoc tools to deal with some little issue, and you don't want to make some honkin-huge app.

Also, the K&R book is pretty awesome. It's totally worth learning C to read the book. Learning to use some cpp macros creatively is also nice, because languages don't have macros (much) anymore.

Bob said...

In 28 years of Aerospace work I have yet to see a single controller programed in anything but C. Not C++ and defintely not Java.

And actually I have never seen a controller using JVM.

I am not commenting on whether or not we should all know C or not. Just the comment about controllers.

later
bobc
http://www.qualitycontrolengineering.com

Jeremy said...

I'm going to have to disagree with you. While I agree that learning C is not necessary for getting a job, it will help you understand the way a machine works and you will have a deeper knowledge of computer science. At the very least, you're going to have a great deal more credibility.

Anonymous said...

I think in C, it's my 'natural' programming language. There's no oop framework to design first, I just code. It's not verbose like pascal. Clickety clack, clickety clack, DONE.

Anonymous said...

ever seen a woman try to drive a stick shift car?

same principle here

matt said...

I agree with several of the other commenters that the original list was bollocks but C nevertheless teaches things that are important to learn as a programmer -- vastly more so than the unremitting dog's breakfast that is C++, for example. C's qualities are usually not sufficient -- a proper functional language is a valuable complement and there are a few other things I'd ideally look for too -- and they may not even be necessary for some roles, but they do contribute to better programming.

However, the real nit I'd like to pick is your response to 7: if you'd picked Perl and Python you might have had a leg to stand on, but there absolutely are not as many Delphi or C# open source projects as C. That's just being silly.

James said...

Matt: Yeah on review, I probably should have changed "just as many" to "a great number" or something like that.

Anonymous said...

I agree with most of what you say, but programming a micro controller in java? Are you on crack?

Anonymous said...

I think you miss completely the point. "There is estimated to be more COBOL code in the world" this is a very old lie, and every day pass is farther from reality. Surely COBOL locs in active applications dont represent more than 0,1% of the total, and that 0,1% is probably far more than real percentage. Practically no new applications have been started with cobol in las 15, now easily are 100x times active programmers than in the 80s.

"A complete fallacy. A program is as fast as its bottleneck and in most circumstances this is the person in front of the keyboard. Also this argument is like saying an Indy car can go 400km/h and an F1 car can only go 360km/h. Therefore an Indy car is faster...."

Hey, your afirmation is the REAL falacy. Although user can be a "bottleneck" surely that user wants a response in a reasonable time. And hey, sometimes doing a thing faster means you can do ten things faster too, and i ask me if it will be true when doing 1000000 things...

Knowing assembler or C does a programmer better. Better because he knows whats works behind the scene. Most actual programmers dont even know what heap or stack are. Or when they apps get interrupted cause OS operations. You easily dont need to know C, but it certainly will help you A LOT, even if wont need it.

James said...

http://en.wikipedia.org/wiki/COBOL

I suggest you read this. Like or not COBOL is still used in Big Business, and there is a lot of new programs written in Cobol everyday.