5 Reasons Why a Beginner Programmer Should Learn C

“C is awful. Tell them to teach you a language that will actually get you a job.”

Haters gonna hate.

The quote above is a comment that a programmer friend of mine recently made when I told him I was learning C in school.

You see, I recently went back to school to get my comptuer science degree. My strongest languages before school were Ruby and Python. So when it came time to choose my first programming class in school, I chose to learn C because I probably would never learn it on my own and I like a good challenge.

Well learning C was definitely a challenge, but it was also extremely helpful.

I recently came across this article which describes C as a “fantastic high level language” and I couldn’t agree more. It inspired me to share my takeaways from learning C and the top five reasons why you should too.

#1 It’s simple! Yes, you heard that right. It’s wonderfully simple.

There’s not a lot to C. You can build a program with a handful of data types, unions and structures, and loops all wrapped up in some functions. It turns out that’s all you really need.

It’s easy to wrap your mind around the structure of a C Program. For example, every program starts in the main function and calls other functions if necessary. I love this structure and think it’s easy for a new programmer to understand. By comparison, it took me weeks to fully understand how to set up a well-organized Ruby program.

There are 29 header files in the C standard library and I only regularly use 5–10 of those. More importantly, in each of those header files there are only a handful of functions — so few that you can actually memorize most of them. With Ruby and Python, I constantly find myself googling to see all the methods available to me, which leads me to my next point…

#2 No shortcuts here. You’ll be forced to practice the fundamentals.

In Ruby, if you want to find all of the repeated permutations of length 4 of an array, guess how you do it:

array.repeated_permutations(4)

Um, that was ridiculously easy.

You can’t do that in one line with C. You have to use logic and practice loops to create permutations in the most efficient way possible. You have to learn what’s actually going on behind the scenes of higher-level programming languages like Ruby.

Of course some people would argue that this isn’t a good thing (what a waste of time!), but for a beginner programmer it’s really important to know what’s going on under the hood.

#3 You can’t escape memory management.

Pointers are a necessary evil of C that often cause confusion and frustration. In case you don’t know, a pointer is a variable whose value is the address of another variable. Pointers allow you to directly access a location in memory, which make them powerful but dangerous.

In order to use arrays, you pretty much have to use pointers, and in order to make a program you pretty much have to group data together in arrays (or some linked structure).

Pointers teach you how data structures are stored in memory. Dynamic memory allocation makes you think about how much space you are using. The term space-time tradeoff finally meant something to me when I saw how I was using space in C.

#4 Fun with bits & bytes & data types

Speaking of memory management, let’s talk about data types. Different data types take up different amounts of space in memory. Some of you might be saying ‘duh’, but it’s really not that obvious in every language. I never thought twice about using an integer versus a char before C.

Well it turns out that one char takes up 1 byte (or 8 bits of memory) of memory when it’s declared, which means that there is a combination of eight 0’s and 1’s dedicated to that char. For example, this is the letter ‘a’ in bits according to the ASCII character set:

0110 0001 // eight bits = one byte

Okay okay, maybe I’m going into too much detail. But this stuff is awesome. This is how a computer knows what you want it to do! And this is the kind of stuff you learn when you learn C.

#5 Best of all, you won’t be scared by new programming languages.

When I first looked at C, I was scared. I was intimiated. I thought ‘what the hell are all of these parentheses and semicolons, and why are there so many words’? Eventually I figured it out and, like anything else, it just took a little practice.

About two months after learning C, I needed to write a program in PHP. PHP syntax requires abundant use of semicolons and curly braces, but I wasn’t the least bit intimidated when I tried to read it. In fact, it took almost no time to read and write PHP. I even knew what to do with this fun question mark:

a = x > y ? x : y;

The moment I realized PHP was going to be a breeze it hit me that my knowledge of C was going to come in really, really handy. It seems like nothing can be worse than pointers and I can’t imagine being that intimidated by new syntax again.

So shake it off

My friend might be a hater and I’m sure there are many more out there.

But hey, the fact that I actually found it funny when I read the recent news that the number of views for the Gangnam Style video broke youtube’s 32-bit integer counter is awesome. And I wouldn’t have truly understood that before I learned C.

Leave a Reply

Your email address will not be published. Required fields are marked *