Sign in
Log inSign up
The Upsides to learning C Part 1

The Upsides to learning C Part 1

Todd's photo
Todd
·Feb 14, 2017

I keep hearing about C, especially in web development communities, in a negative light and portrayed to be this extremely difficult, unwieldy, old grandpa of a language that needs to die. This is simply not true, so instead of whine about it, I decided to write an article on this subject here. I'm going to break it down to address key points. Before I start, I want to make it very clear that I am not telling you "C is 'better' than whatever language you are currently using, and I am also not asking you to go to work and try to convince your boss to switch everyone to C, that would be silly. However, I am providing an alternative view of the language from the perspective of a person who first learned C# and JavaScript, and then got into low-level programming with C and assembly. Of course we don't live in a flat world where things can be simplified to "better or worse" all the time and in reality, it comes down to best for the job. I am simply writing my personal account on this and if it helps you make a realization/try some C in your spare time, I'm happy! :)

C is Hard

What is your definition of hard? No, really... Think about this for a second. For different people, this varies tremendously. C is actually very easy in some ways, and more difficult in others. Let me break it down:

The easier parts:

  • C doesn't have as many built-in features and extra weight as other, more "fully featured" languages such as C++, C#, and Java. But this doesn't come at the price of power... C is still perfectly capable of everything that those languages are, only sometimes it may require a bit more typing (or writing your own functions/library); that's all. This makes the language fundamentals much more concise to learn. Compare a basic C book such as K&R C or The GNU C Book in pages to books on C++ or C# and you will see what I mean real fast. Additionally, I've never met a programmer who complains about typing in too much code; most of us love that part. Generally, the complaints come from not enough coding!
  • C's syntax, because it's not an object-oriented language, can often be more concise and "less cluttered" in nature. I could try and go into all the specifics, but the best thing to do would be to view these two examples:

  • C# Example

  • C Example

Of course the actual implementation varies and yes there is ugly C code and of course there is concise C# code... But in general, if you do programming in both languages often, you will find that C is usually less verbose.

  • Learning C means you'll learn the fundamentals - A lot of people like to gloss over this one and pretend it's not true, but it is. The reality is, at the end of the day, there is a real physical processor in your machine, and it is executing machine code, not pretty Python, JavaScript, C#, etc... It is also running operations and moving numbers in and out of memory at over 2-3 billion cycles per second. While there is absolutely a valid argument that for your and your team's use cases, you may never need to do any low-level programming, and you may never need C at all for your job, there are still things to be learned in the C language and x86-64 assembly that will help you tremendously in understanding and relating to every day problems, and communicating with other programmers.
  • A stark reminder of how important these low-level programming concepts are is shown to us every day by hackers. There's a reason hackers and reverse-engineers are using assembly and C code to do most of their work - it exposes the reality of what I just mentioned - while so many developers are thinking we're "beyond" the C and assembly days, these exploiters are tearing apart bits and bytes and finding all kinds of holes day in and day out. Reverse engineers know low and high level programming, so why shouldn't software engineers?

  • Another such example is pointers. So many programmers are scared of pointers. Of course when you add another element into the mix, there is room for mistakes, but being scared of learning pointers is literally like being scared of using addresses to find a destination. You see, from learning C and assembly, I know that at the end of the day, a memory slot is at an address and it either holds a value, an instruction, or an address of another value. When I first learned JavaScript, I struggled hard with callbacks and recursion. But after learning C and assembly, I came back and immediately knew what was going on in a JS callback (at least in theory, this could vary due to the JS interpreter engine) - the address of the callback's first instruction is passed into a function as an argument, placing it in that function's memory space. Now, when it is time for the callback to be called, the calling function simply directs CPU execution to that callback's first instruction's memory address where the callback is executed.

  • Being able to think of things in the above way goes a long way in helping to understand concepts in other languages. Even though the languages themselves are often said to "not have pointers," this isn't really true, it's more like they are hiding pointers from you but underneath there, trust me, pointers are being used.
  • Another useful example is how class objects are created. You've probably heard of the stack and heap and may or may not know what they actually are. One thing that's cool about C is that it forces you to have a much more intimate relationship with the stack and the heap... Once you get good with C, those interview questions will be a walk in the park.
  • It doesn't give you any crutches - Let's face it - some of the smartest and best programmers are masters at algorithms and data structures. In fact, people go out of their way to try and improve on sites such as HackerRank and Sphere Online Judge (SPOJ)/ C doesn't provide you many data structures and algorithms and it makes you either write your own or go find someone else's. This fact alone has pushed me to write my own library code more than other languages, which have challenged me in amazing ways and forced me to learn the fundamentals of programming rather than just using someone else's code all the time. This has amazing benefits in helping your problem-solving skills improve, which is a huge factor in your performance in white-boarding interviews and on the job as well.
  • The added benefit to this is also that you end up spending less time fighting with other peoples' code and libraries (making version 1.5.3.54.2 of your ORM cooperate with version 4.3.2.5 of your database software and 6.5.3 of your dependency injection framework, etc...) and more time solving real programming problems.

And the more difficult parts of C:

  • Learning concepts such as pointers up-front in your programming career is very helpful in your understanding down the road, but does require some extra effort and overhead to start with.
  • C also may not have as much "instant gratification" factor if you are totally new to programming. Most people when they are new just want to see something work, and since C is often used for a lot of "behind the scenes" stuff, a new programmer may begin questioning their choice of learning C when their buddies are making beautiful-looking webpages in JavaScript, HTML, and CSS in week 1.

That's all for today. I may make a part 2 soon. Take care!