Why You Want to Learn C in Today’s Programming World

If you flip through some of the “I want to learn C” questions on StackOverflow, you’ll find an interesting trend.  That trend, is that at least one person will try to disuade the user from learning C, siting that languages like C# and Java are better, and don’t require the programmer to worry about memory management.  A good example is this question.

Before we go any further, I think it is important to mention that I make a living doing development in C# and that I have also recently picked Java backup so i could write some programs for phones running Google’s Android OS.  So I have experience in both of these popular “managed” languages.  And I should also note that both languages are very good languages and allow a developer to accomplish things a lot quicker (and sometimes easier) than in a language like C.  With that disclaimer out of the way, lets move on.

The Importance of C

I think to understand why C is important as a language you have to look back to when C first came about.  When C first came out there were languages like Assembly, Pascal, and FORTRAN.  All of these, while nice were either hard to use or understand.  When C came along the idea of “high level” was still pretty foreign.  The C language changed that.  It was easy to understand, allowed low level access to things like memory, and was fast.  C did a lot to change how people looked at programming and made it slightly easier for people to write code.  One might equate going from Assembly to C is like going from C to Java (or C#).  There’s just that much difference in how easy it is to get things done that a whole new level of people can program.

Why C is Still Relevant

So in today’s languages, a programmer does not have to concern themselves (too much) with memory management, or even performance (not like before anyway).  Computers are so much faster and come with so much more memory than before that things like memory management and maximizing performance are not top considerations anymore.  Use to be, you had to pay attention to memory because you had less than 1 megabyte of it.  Your processor weren’t as fast so every computation had to count in a big way.  But in languages like C# or Java, these aren’t top concerns.  Both have garbage collectors (that you as a programmer can’t directly control), they both run on top of their own runtime so there’s an added layer when it comes to running the application.  Both C# and Java are extremely high level languages, a lot of stuff is written for the developer already and so both have awesome libraries ready for use.

But could you write an operating system in C# or Java?  Even if you could, should you?  If you need something to run its fastest, shouldn’t it talk to the hardware as directly as possible?  This is where languages like C (and even C++) come in.  The C language doesn’t run on top of a runtime.  It compiles into machine code, not Java Byte Code or IL code (C#).  There are performance gains to using a language like C when writing drivers, massive computation programs, and even libraries.  The less your program as to go through to talk to the hardware, the faster it’s going to be.

Caveats

Of course, a language like C comes with its own set of problems.  For starters, there is no such thing as garbage collection.  When writing applications in C, you have to make sure you take care of your memory, and you have to do so in an efficient and correct way.  Otherwise you get memory leaks which can cause performance to degrade.

Working with C is no different than working in any other language, you have to know how to use it.  You have to make sure you write good clean code, handle your memory correctly, and make your calculations count.  You can write bad C code, just like you can write by Java code.

Conclusion

I think to tell someone that they shouldn’t bother with C does a disservice to programmers. Programmers should know and understand where their languages come from. The Java and C# languages are heavily rooted in C. But I think the idea that it is better to code something in C# rather than C (or C++) is a misnomer, and other facts need to be considered before such a statement is made. If you’re interested, I found some benchmarks at Dr Dobb’s website for Java, C#, and C++. Give them a look to see what kind of performance you get out of the various languages.

This entry was posted in programming and tagged , . Bookmark the permalink.

2 Responses to Why You Want to Learn C in Today’s Programming World

  1. chaz2010 says:

    Excellent post. Having just learned that Oracle is written in C for the very reasons that you mention, I completely agree with you.

  2. chaz2010 says:

    Excellent post. Having just learned that Oracle is written in C for the very reasons that you mention, I completely agree with you.

Comments are closed.