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.
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.
Year | C | C++ | Java | |
---|---|---|---|---|
1970 | Unix time begins. | |||
1971 | Apollo 14. | |||
1972 | Pong. | |||
1973 | C invented(ish) | Watergate scandal. | ||
1974 | Rubik's Cube. | |||
1975 | Microsoft. | |||
1976 | Apple. | |||
1977 | Voyager. | |||
1978 | K&R C | RSA. | ||
1979 | "C with Classes" in development | Alien. | ||
1980 | Pac-man. | |||
1981 | Donkey Kong / Mario. | |||
1982 | First computer virus. | |||
1983 | Renamed to C++ | GNU. | ||
1984 | Macintosh. | |||
1985 | "The C++ Programming Language" released | Windows. | ||
1986 | First laptop computer. | |||
1987 | DNA fingerprinting. | |||
1988 | Photoshop. | |||
1989 | ANSI C / C89 | C++ 2.0 | Stealth Bombers. | |
1990 | C90 (== C89) | World Wide Web. | ||
1991 | Java project started | Sonic. | ||
1992 | Batman Returns. | |||
1993 | PDF. | |||
1994 | PlayStation. | |||
1995 | Java Alpha/Beta | I was born. | ||
1996 | Java 1.0 | Google. | ||
1997 | Java 1.1 | Space Shuttle Discovery. | ||
1998 | C++98 | Java 1.2 | XML. | |
1999 | C99 | HTTP/1.1. | ||
2000 | Java 1.3 | Y2K. | ||
2001 | Wikipedia, Windows XP, iPods, C#. | |||
2002 | Java 1.4 | JSON. | ||
2003 | C++03 | Volkswagen Beetles stop being produced. | ||
2004 | Java 5.0 | Facebook. | ||
2005 | YouTube. | |||
2006 | Java 6 | Twitter. | ||
2007 | C++TR1 | Portal. | ||
2008 | I started learning C++. | |||
2009 | Minecraft. | |||
2010 | Inception. | |||
2011 | C11 | C++11 (C++0x) | Java 7 | Qubits. |
2012 | The world didn't end. | |||
2013 | Antichamber. | |||
2014 | C++14 (C++1y) | Java 8 | This article was written. | |
2015 | GTAV on PC. | |||
2016 | Java 9? | Juno spacecraft arrives at Jupiter. | ||
2017 | C++17? (C++1z) | Classified JFK declassified. | ||
2018 | Java 10? | Launch of the Mars sample return mission. | ||
2019 | Copyrighted works from 1923 enter the public domain. | |||
2020 | C++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.
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.
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.
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++".