Ask HN: Is it worth it to learn C in 2020? - zabana
======
ktm5j
I say yes because, as others have pointed out, C is at the base of nearly
everything. If not C then you should learn _some_ systems level language, be
it C, D, rust or whatever. If you want to know how modern computing actually
works then that's the way to do it.

You'll learn lessons that will teach you how to avoid common pitfall mistakes
in higher level languages. And you'll be able to interop with C/C++ libraries
which can be quite useful. And your code will run faster than most other
languages can achieve. There are lots of reasons to learn C even today.

------
dinkleberg
What type of projects are you trying to build? Are you working on embedded
technology or are you building web apps? The type of environment you work in
will help decide. C is still a relevant and powerful language, but there are
more modern alternatives in the same space like Rust.

------
yulaow
If you want to work, for example, in embedded systems it's a must

------
WheelsAtLarge
Yes. Many current hot languages are based on the C's structure plus there are
millions of lines of C code that need maintenance. It's worth learning now and
it will be worth learning 10 years from now.

------
ThrowawayR2
Only matters if you want to work in embedded devices/IoT, operating systems,
any other type of systems development or high-performance development, and
some segments of game development or games middleware.

------
westurner
The GNU/Linux kernel, FreeBSD kernel, Windows kernel, MacOS kernel, Python,
Ruby, Perl, PHP, NodeJS, and NumPy are all written in C. If you want to review
and contribute code, you'd need to learn C.

There are a number of coding guidelines e.g. for safety-critical systems where
bounded running time and resource consumption are essential. These coding
guidelines and standards are basically only available for C, C++, and Ada.
[https://github.com/stanislaw/awesome-safety-
critical/blob/ma...](https://github.com/stanislaw/awesome-safety-
critical/blob/master/README.md#coding-guidelines)

Even though modern languages have garbage-collection that runs whenever it
feels like it, It's helpful to learn about memory management in C (or C++).
You'll appreciate object destructor methods that free memory and sockets and
file handles that much more. Reference cycles in object graphs are easier to
handle with modern C++ than with C. Are there RAII (Resource Acquisition is
Initialization) "smart pointers" that track reference counts in C?

Without OO namespacing, in C, function names are often prefixed with
namespaces. How many ways could a struct be initialized? When can I free that
memory?

When strace prints a syscall, what is that?

Is it _necessary_ to learn C? Somebody needs to maintain and improve the
C-based foundation for most of our OSs and very many of our fancy scripting
languages. C can be very unforgiving: it's really easy to do it wrong, and
there's a lot to keep in mind at once: the cognitive burden is higher with C
(and then still with ASM and WebASM) than with an interpreted (or compiled)
duck-typed 3GL scripting language with first-class functions.

What's a good progression that includes syntax, finding and reading the libc
docs, Make/CMake/Autotools, secure recommended compiler flags for GCC
(CPPFLAGS, CFLAGS, LDFLAGS) and LLVM Clang?

C:
[https://learnxinyminutes.com/docs/c/](https://learnxinyminutes.com/docs/c/)

C++:
[https://learnxinyminutes.com/docs/c++/](https://learnxinyminutes.com/docs/c++/)

Links to the docs for Libc and other tools:
[https://westurner.github.io/tools/#libc](https://westurner.github.io/tools/#libc)

xeus-cling is a Jupyter kernel for C++ (and most of C) that works with
nbgrader. [https://github.com/QuantStack/xeus-
cling](https://github.com/QuantStack/xeus-cling)

What's a better unit-testing library for C/C++ than gtest?
[https://github.com/google/googletest/](https://github.com/google/googletest/)

~~~
zabana
Amazing comment, thank you for your detailed input and the awesome resources.
I want to get into C because I like network and system programming but lack
the underlying knowledge and experience. These links will help me start on
that new path. Very much appreciated sir :)

~~~
westurner
For network programming, you might consider asynchronous programming with
coroutines. C++20 has them and they're already supported in LLVM. For C, there
are a number of implementations of coroutines:
[https://en.wikipedia.org/wiki/Coroutine#Implementations_for_...](https://en.wikipedia.org/wiki/Coroutine#Implementations_for_C)

> _Once a second call stack has been obtained with one of the methods listed
> above, the setjmp and longjmp functions in the standard C library can then
> be used to implement the switches between coroutines. These functions save
> and restore, respectively, the stack pointer, program counter, callee-saved
> registers, and any other internal state as required by the ABI, such that
> returning to a coroutine after having yielded restores all the state that
> would be restored upon returning from a function call. Minimalist
> implementations, which do not piggyback off the setjmp and longjmp
> functions, may achieve the same result via a small block of inline assembly
> which swaps merely the stack pointer and program counter, and clobbers all
> other registers. This can be significantly faster, as setjmp and longjmp
> must conservatively store all registers which may be in use according to the
> ABI, whereas the clobber method allows the compiler to store (by spilling to
> the stack) only what it knows is actually in use._

CPython's asyncio implementation (originally codenamed 'tulip') is written in
C and IMHO much easier to use than callbacks like Twisted and JS before
Promises and the inclusion of tulip-like async/await keywords in ECMAscript.
Uvloop - based on libuv, like Node - is apparently the fastest asyncio event
loop. CPython Asyncio C module source:
[https://github.com/python/cpython/blob/master/Modules/_async...](https://github.com/python/cpython/blob/master/Modules/_asynciomodule.c)
Asyncio docs:
[https://docs.python.org/3/library/asyncio.html](https://docs.python.org/3/library/asyncio.html)

(When things like file or network I/O are I/O bound, the program can yield to
allow other asynchronous coroutines ('async') to run on that core. With
network programming, we're typically waiting for things to send or reply.)

Return-oriented-programming > Return-into-library technique is an interesting
read regarding system programming :) [https://en.wikipedia.org/wiki/Return-
oriented_programming#Re...](https://en.wikipedia.org/wiki/Return-
oriented_programming#Return-into-library_technique)

------
shakkhar
Most certainly. I do suggest C++ over C though, for a higher paying job.

------
t312227
imho: always

especially if you are in to hardware, embedded, hpc, ... usecases.

------
streetcat1
Maybe if you want to write a kernel driver or a file system.

------
borplk
You can't go wrong with it. But for what purpose?

------
livealife
yes

