Comment by dilippkumar

3 years ago

I spent several years writing C code, then a few years writing C++ and now moving into Rust.

My take: Coding in C will teach you a two unique skills:

First, mastering working with pointers will inevitably lead you to debugging cache-miss related performance issues, virtual vs physical addresses when dealing with MMUs and a couple of other low level CPU details that are hard to learn about any other way (yes, this can also be done with C++).

Second, Because C is a barebones language, you’ll have to build everything yourself. Linked lists, hash tables, queues, binary search trees - all of it! And since you are working with pointers, a lot of the data structures and why they matter will make sense at a level that is impossible to grasp with say python (For example, any C programmer who picks up the usual university textbooks on algorithms and data structures looking for a reference to implement a hash table will end up disappointed- most books tell you how hash tables work, but very few tell you how to implement a hash function correctly - and with C, this matters a lot!)

C++ trades off some of C’s language simplicity in exchange for developer velocity. Hash tables, vectors etc are all taken care of for you. But this is actually a dangerous trade off: C++ gives you a language that will not fit in your head, and you can never be entirely certain about the behavior of code hidden from you by design.

Rust makes a ton of sense as a C++ replacement. It takes the same trade off that C++ did (give up language simplicity for developer velocity) but also adds guard rails around to help keep things sane.

I am convinced that rust is the future in every place where C++ makes sense today.

C is different. Yes, it suffers from many of the same bad things as C++. However, people who write C also work differently: they are used to building everything from scratch, they know their projects need more time to complete, they can look at almost every single line of code and tell you roughly what machine code it will compile down to. The language is small enough that it everyone knows all of it, most agree on the best way to do things and critical bugs are often spotted by just recognizing that some code doesn’t appear to follow well known patterns for implementing something (see how the OpenBSD community find bugs for example).

In short, it’s hard to recommend rust over C because they kind of come with different developer ethos. But Rust over C++ is a no brainer any day. And Rust over C makes sense any time C++ over C makes sense (which is the case for most C projects)

One interesting quote about rust in the context of OpenBSD [1]

> For instance, rust cannot even compile itself on i386 at present time because it exhausts the address space.

C is not going away anytime soon.

[1] https://marc.info/?l=openbsd-misc&m=151233345723889&w=2