DEV Community

Discussion on: To C/C++ Or Not to C/C++

Collapse
 
louy2 profile image
Yufan Lou

The problem I have with C/C++ is not that they are difficult, but that teaching them does not lead to reliable software. There is not enough time in any undergraduate curriculum to go into the undefined behaviors in C/C++, and those come back to bite the whole industry in the form of CVEs.

For every CS undergraduate today I hope they can finish Software Foundations from University of Pennsylvania. Hopefully every engineer, too. The course teaches you Coq, a formal verification system, with a functional formal specification language and a procedural proof language. This is truly how a computer works. Assembly is after this, because the circuit logic of a working CPU architecture needs to be formally verified in a similar system before the chips can go into production.

Coq teaches you how to reason about software. This is the biggest struggle which I have witnessed. A student with no prior knowledge does not tell keyword from function, variable from type, or function from variable. It is a whole new language. They need to learn by trial and error. We all did. But in C/C++, simple mistakes can lead to cryptic error messages, even referring to internals unrelated to the topic at hand. The best students Google their way out, while the others are left behind. With Coq, the interactive reasoning environment gives proper instructions to students on their trials and errors, while the logic system is permissive enough to model the topic in a non-distracting way.

Software Foundations starts from basic logic, then goes on to teach a theory of programming languages. Programming language is the tool we use as developers. Not knowing it thoroughly is like a craftsperson not knowing their tools. A lighter and informal alternative of this is the Structure and Interpretation of Computer Programs. After that, it introduces reasoning about software systems built on top the language developed in the chapters before.

Although a managed language helps a lot, it does not cover every use case of a unmanaged language. That's where Rust comes in. Rust has apparently been enough for many companies to replace C/C++. Rust teaches you how to reason about memory lifetimes, and concurrent memory access. University professors are creating courses for Operating Systems written in Rust, such as UW CS451 and Stanford CS140e. The error messages from the Rust compiler are not only comprehensible, but also helpful.


For fields not requiring the stability of a long running server or infrastructure, such as computational art, data analysis and visualization, and business process mining, C/C++ is just a mismatch. They are much better off learning Python or JavaScript to boot.