C++ is not C "with classes"

Please. Stop lumping C and C++ together. It's wrong. Every time you write "C/C++" or "C/++", somewhere, a C++ programmer pulls their hair out and Dennis Ritchie rolls over in his grave.

Although C++ was originally a derivation of C, and was originally referred to as "C with Classes", it has changed over the last few decades and is nothing like C. Sure, the syntax looks the same, but that can be said about Java too, and when's the last time you saw the phrase "C/Java"? It's not a common phrase, and "C/C++" shouldn't be a common phrase either.

I don't know C. I have, however, passionately studied C++ for years. Idiomatic C is often contrary to idiomatic C++. I don't think I could ever just sit down one day and start writing good C, no matter how good I am at C++.

I'm sure many of you know about the theory of evolution and the common misconception that humans evolved from apes; humans and apes evolved from a common ancestor. C++ and C evolved from a common ancestor too - ancient C.

When I say "C" or "C++" or "Java", I am referring to the latest standard or version. At the time of writing, the latest standards are C11, C++14, and Java 8. If you don't know that there are different standards of these languages and that languages change drastically over the years, you shouldn't call yourself a programmer.

That's a pretty bold thing of me to say. In fact, it's in bold text. The point is, everything short of the laws of physics changes over time, including programming languages. If you aren't aware that C++ has changed twice in the last decade, you're out of the loop.

A Brief History Lesson

Below is a table showing the history of C, C++, and Java standards/versions. The table spans a whopping 50 years (five decades)! The bolded year is the year for which this article has been updated.

1970Unix time begins.
1971Apollo 14.
1973C invented(ish)Watergate scandal.
1974Rubik's Cube.
1978K&R CRSA.
1979"C with Classes" in developmentAlien.
1981Donkey Kong / Mario.
1982First computer virus.
1983Renamed to C++GNU.
1985"The C++ Programming Language" releasedWindows.
1986First laptop computer.
1987DNA fingerprinting.
1989ANSI C / C89C++ 2.0Stealth Bombers.
1990C90 (== C89)World Wide Web.
1991Java project startedSonic.
1992Batman Returns.
1995Java Alpha/BetaI was born.
1996Java 1.0Google.
1997Java 1.1Space Shuttle Discovery.
1998C++98Java 1.2XML.
2000Java 1.3Y2K.
2001Wikipedia, Windows XP, iPods, C#.
2002Java 1.4JSON.
2003C++03Volkswagen Beetles stop being produced.
2004Java 5.0Facebook.
2006Java 6Twitter.
2008I started learning C++.
2011C11C++11 (C++0x)Java 7Qubits.
2012The world didn't end.
2014C++14 (C++1y)Java 8This article was written.
2015GTAV on PC.
2016Java 9?Juno spacecraft arrives at Jupiter.
2017C++17? (C++1z)Classified JFK declassified.
2018Java 10?Launch of the Mars sample return mission.
2019Copyrighted works from 1923 enter the public domain.
2020C++20?Russia mines helium from the moon.

I included Java because at least the average Java user is aware that there is more than one version of Java, and it should clue you in that there are also multiple standards of other languages too. For C and C++, the different versions are called standards.

Looking at this table, a lot happened in 2011. In fact, I consider C++ to have become a completely new language with C++11 - that's how different it is from C++03. But it was already quite different from C by the time it was C++03.

The way I write code in C++11/14 is completely different from the way I write code in C++03 legacy projects. But, even in C++03, the way you think and write code is completely different from in C.

Let's look at C

C has an interesting story. It inspired C++, and then when it saw C++'s const-correctness, it adopted it. But then C looked at the rest of C++ and was horrified, and ever since then has been trying to distance itself from C++. C++ has also been distancing itself from C, but not to spite C - it's more a movement to become more modern.

For me, the biggest thing that makes C++ different from any other language, especially C, is RAII. C++ makes pointers obsolete and downright wrong. C, however, embraces pointers and even has fancy new keywords to restrict how they are used.

Like I said, I don't know C. But I know enough to know that C is drastically different from C++ in more ways than one. Sadly, I have to contrast them because apparently there isn't already enough contrast.

There are many who will wrongly say that C is a subset of C++ or that C++ is a superset of C. Ignoring the fact that there are valid C programs which are invalid C++ programs, let's look at the implications of such statements.

Such statements suggest that by learning C++, you have already learned C. I have been passionately studying C++ for several years and am highly proficient in it, but I doubt I could ever write good C code. Sure, I can definitely write decent C code, but it would be a struggle. I don't know how to think in C any more than I know how to think in quantum mechanics.

The above statements suggest that a C programmer should easily be able to write in C++. While this is somewhat true, it is a very bad idea. I've seen many "help me" posts from people who can't decide whether they want to use C++ or C, and often mix the two because they can't tell the difference.

Let's look at C++

C++ has RAII, smart pointer wrapper classes, and a whole lot of idioms that are either impractical or impossible in C. The ones which are possible in C don't really make any sense in C. Idiomatic C is usually in complete opposition of idiomatic C++.

C++ also has template metaprogramming, which, while controversial, is something I consider to be half of the language. The new <type_traits> header is one of my favorite headers. C++ also now has a <chrono> time library and a <random> RNG library.

Lambdas were something C++ sorely needed too, and it got them in C++11. C++ also got std::function, a polymorphic function wrapper. In C, you need to have a user data argument for most callbacks, but with C++, you use std::function and std::bind.

Even before C++11, the C++ iterators, algorithms, and containers library is quite impressive. They mesh together very well and make it so most things you would want to do involving iteration, algorithms, or lists/sets is either trivial to implement or already implemented for you.

A good example of C vs C++ is std::string - C++'s string class. In C, there is no such thing - instead, a pointer to a character is almost always pointing to the first character in a null-terminated string. C++'s std::string is not null-terminated and can contain null characters. Oh, and it manages its own memory.

Not to be judgmental

I'm not trying to say one language or the other is better - they each have their use and I don't think either one will fall out of use for many decades. However I am trying to say that they are very different languages and should not be lumped together. It's not right. Could you imagine lumping together the C# folks with the Python folks? I don't see any "C#/Python" sections on programming sites.

So, please. C and C++ are different. Stop using "C/C++".