C
is a system programming language which is old but with “bad” fame: undefined behavior, notorious memory related bugs, etc. Especially with Go
and Rust
having gone viral right now, C
seems already forgotten by people. Nevertheless, IMHO, C
is still a thing which is worth for you spending some time on it.
Whether you are are a C
novice or a C
veteran,I highly recommend you read Modern C if you haven’t read it before. Then you will find C
also evolves stealthily and is not as primitive as you think. E.g., C11
has defined standard thread APIs like C++
has done, which makes C
more like a “modern” language, not an outdated thing. You may get a new perspective of C
from this book.
Regardless if you are a systems language programmer, DevOps, performance engineer or wear other hats, the more you know about the Operating System, the more you can do your job better. Take all prevailing Unix-like
Operating Systems as an example, from kernel to command line tools, they are almost implemented in C
. To study related source code can make you delve into Operating System internal deeper. E.g., I knew there is a taskset
command which can bind specified process of a dedicated CPU
, but I wanted to know the magic behind it, so I went through its code. Then I learned 2
things:
a) There is a “/proc/%pid/task
” folder which records thread information of process;
b) taskset
actually calls sched_setaffinity and sched_getaffinity APIs to attain its goal.
Last but not least, because C
is so “low-level”, you can leverage it to write highly performant code to squeeze out CPU
when performance is critical in some scenarios.
Although I have listed many reasons which I think you should learn C
, you may have sufficient excuses to refuse to dabble into C
too. It doesn’t matter. But if you want to give C
a shot, firstly you should not be scared of it. There are many ways of writing wrong C
code, but you only need to make sure what you write is correct and in defined behavior, that’s all about C
programming.
>There are many ways of writing wrong C code, but you only need to make sure what you write is correct and in defined behavior
The “don’t make mistakes” advice is as universal as it’s useless. 😉
>Take all prevailing Unix-like Operating Systems as an example, from kernel to command line tools, they are almost implemented in C
In the 70’s you had to know a bunch of assembly languages to study or contribute to then-existing OSes. They all have been rewritten in something else.
>because C is so “low-level” you can leverage it to write highly performant code to squeeze out CPU when performance is critical in some scenarios.
You can also use a well-design language that compiles to native code instead. Ada for systems stuff (Ada 2012 has a formal verification tool integrated). Julia or Fortran 95/2003 for number crunching.
The dichotomy is not C vs Ruby. It’s 60’s design vs the other 50 years of programming language research. By treating C as something else than legacy, you’d be missing out a lot.
C is still KING of the embedded world
I agree totally. C is classic language which should be learned, not like Go or other languages which are all about hype.