DEV Community

Erik Dietrich
Erik Dietrich

Posted on

To C/C++ Or Not to C/C++

More than 20 years ago now (wow, I'm old), I was in the middle of a computer science program at my alma matter, Carnegie Mellon University.

And, at that time, they had a pretty strong opinion about what programming language CS students, such as myself, should learn and use: C++ (and also, while were at at it, C).

Learning C++ and C as my first languages wound up serving me well. But having learned probably 10 languages between then and now, I can't help but think, "wow, a managed language (or whatever) might have flattened my learning curve and made life easier."

So, here's my question for the group in 2020. Should new programmers learn C/C++ first?

  • Yes, learn those and everything else is easy!
  • No, newbies should work themselves up to either C or C++

Latest comments (27)

Collapse
 
aregtech profile image
Artak Avetyan

I didn't start with C/C++, but something simpler. In my time, it was Basic, Fortran, Turbo Pascal. But I always wanted to develop with C/C++ and I did. I think, it does not really matter what programming language you learn, but it matters what technology you know. At the end, who cares how pointers and multiple inheritance work. But, for example, if you don't know anything about event-driven or asynchronous programming, the knowledge of syntax may worth nothing. And when use technologies, we all learn new programming and scripting languages.

And at the end, C++ is not so complex, but it is very flexible. Some people love C++, some others hate. It is better if newbies try C++ when already have some experience, because they might discover another universe :)

So, my answer is No. Start with something easier :)

Collapse
 
jm4r profile image
Mariusz JaskΓ³Ε‚ka

Stop treating C and C++ as one language. As for 2020, the concepts of both are completely different.

Collapse
 
kspeakman profile image
Kasey Speakman • Edited

Starting with C/C++ is like starting in the middle and is not an optimum approach to a curriculum IMO.

If you want to build someone up from the basics, the curriculum should probably start with computer architecture (which was a 3rd or 4th year class when I was in college), then assembly, then C, C++, and so on. This kind of approach shows you the progression of abstraction and how we got to where we are now.

But if you want to start with problem-solving, the curriculum should start at a higher level, like python. Then drill down into the details. Like an assignment which purposely leads the student to cause a stack overflow exception. That paves the way for future topics on hardware constraints and language design.

Starting with C/C++ attacks the student from both spheres at once. I believe an incremental approach (from either direction) would better accomplish the goal of educating students.

My own college curriculum started with C/C++, but supports my hypothesis above. I had the benefit of taking Pascal in high school, which was a higher-level approach to structured programming. In my first college programming class (which was C), the professor stated it would be a weeding out class where 50%+ would fail or drop. I showed up exactly 3 times to lecture - first day, midterm, and final - and was an unofficial lab assistant because people asked me to help when I finished early. I made an A, but not because it came naturally to me. It was because I already had a foothold on the problem solving from a higher level language.

Collapse
 
vdedodev profile image
Vincent Dedo

I would pick a third option, learn C or C++, but don't limit yourself to one language. At uni we covered several languages (Haskell, C, Java, assembly) with some overlap, every time we started a new one it felt like we were progressing faster.

I think being exposed to a low level language and having to work through some of the pain is worth the effort, but new programmers shouldn't be stuck with that until they've mastered the language. I'd say do enough with memory management and pointers so you can appreciate an "easier" language like Python.

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.

Collapse
 
mburszley profile image
Maximilian Burszley • Edited

Everyone else can sling CSS and Javascript and UITableViews if making money is all they care about. That should be a vocational school, and you come out of that with a certificate. But it ain't computer science.

Ooof. All that gatekeeping from a philosophy major.

Collapse
 
pris_stratton profile image
pris stratton

Anything that gives you a new perspective has to be good. C does, as does Haskell. Maybe that’s a cliche but it’s true.

Collapse
 
jeikabu profile image
jeikabu

First, no.
Eventually, yes!

Collapse
 
kwstannard profile image
KW Stannard

I had a class that used C++ and it was bad. I barely remember anything about what we were supposed to be learning because I had to spend all my time fighting the language.

Collapse
 
mabla0531 profile image
Matthew Bland • Edited

Having worked as an instructor for new programmers, I have a strong opinion about this: definitely not. C++ is incredibly daunting for anyone who hasn't been working with computers in some way already (memory pointers is where every single one of them come to a screeching halt and likely fail the class, I've seen a lot of really smart kids change majors because my stupid university teaches C in comp sci 1, to mostly engineering majors). From what I've seen beginners without familiarity with computers or programming hate the syntax and it's very cryptic to people that don't know how languages work already. That's not to say I think they shouldn't learn it, it teaches great fundamentals of programming and techniques that can carry over to java python and JS (🀒) if they dont actually want to go into a job with systems design.