C versus C++

[linkstandalone] C v. C++

I recently joined the ACCU and I’ve been thinking / reading a lot about these two languages. They both have very large entrenched user bases with very strong opinions. I’m by no means an expert C++ programmer but I am always learning and trying to do my best to stay up to date with all the new features. Between the two communities there exists a large divide in their philosophy of use. Some members of these communities can be very opinionated about the language of choice. The breakdown goes something like this:

This is of course a generalization. There are very small and minimal C++ projects and large behemoth-like C projects. In any case I think the general attitude is accurate; especially when we look at how the ISO committees treat these languages. C++ tends to grow ever larger at each three year interval, while C grows slowly and sometimes even shrinks. Working with C++ I know I cannot keep all of its features in my head and nor can I use all the features in each program. This makes me think; at what point does a language become too large?

Since I cannot hold the entire C++ standard in my head currently, does it even matter that it grows larger? Is minimalism a worthy virtue to strive for in this area? Maybe it is more work to write C programs since the language does not provide all of the useful abstractions that C++ does. If one isn’t going to write all their own C code by hand and decides to use a library to help them out are they any better served by using the smaller of the languages. In other words wouldn’t you be better served by using a standardized library that was guaranteed by the language to be included?

There was the famous post by Linus Torvalds talking about how much he dislikes C++ and its programmers. I think there is some truth to his comment about using new abstractions and then gettign chained to them. Against his other point; people can write just as terrible C code as they can C++.

Why pick C++ over C?

One of the things I do prefer about C++ is its support for functional programming. I love lambdas. This doesn’t mean that C++ covers this area the best. I really wish there the attitude of immutability by default like there is in Rust. That is a whole other rabbit hole which deserves its own post.

Jack of all trades, master of none

I think looking at the attitude of the Python language here highlights and interesting issue. Guido Van Rossum is of the opinion that there should be the One Way to solve a problem. To be exact he wrote, “There should be one– and preferably only one –obvious way to do it.” I think this stemmed from the fact that Perl was much more popular at the time and it was generally considered a very expressive language where there could be many different solutions to the same problem. Then, a programmer who comes along to read or improve anothers program, must first decipher what problem was being solved by the original writer. This contributed to the reputation of Perl being a write-only language. Is it better to give the programmer expressiveness over readability? How do these ideas transfer over to the world of C++?

OOP

Maybe its just my preference towards the functional paradigm, but I don’t think that Object Oriented Programming is all that it was hyped up to be. I think that in many cases it makes a lot of sense. Other times you get this nightmare of nested class structures. OOP was touted as the programmers saviour during the 90’s. I remember reading this quote from Dijkstra where he says:

“Object-oriented programming is an exceptionally bad idea which could only have originated in California.”

I think at this point it’s obvious that OOP has not solved the woes of the programming world and it does not fit every use case of every problem.

Portability?

It may be a fair statement to say that there are more ISO compliant C compilers than there are C++ compilers. For most people there are really only three C++ compilers; gcc, clang, and msvc. Yes, there are other pay-to-play C++ compilers you can use like Intel, IBM, or PGI; which reminds me that I need to try some of those out. But how many people are using those.. What significance does this hold? Does maximum portability acctually matter for your project? Will you code ever run on a obscure microcontroller? If you are writing a 3D game engine, it really only makes sense to target desktop style machines supporting your Big 3 compilers.

On the other hand the Doom engine was written in portable C, and look how that turned out..

Conclusion

All in all I’m still working on these questions myself. These are mostly philosophical and without straightforward solution. Maybe there is no One True Way. Maybe I should just become a Lisp programmer. That’s where the real minimalism lies.