#FredsOpinion

What I love about Java – and why I hate C++4 min read

I recently announced that I would start posting technical posts from time to time and when I brainstormed today’s subject, I realised, that I didn’t post any single technical article since then. For my excuse, most of the stuff that I would like to write about is under an NDA, hence, I currently don’t have permission to write about it, but I asked for permission to be at least able to write about some parts of it, so hang tight 🙂

I know that programming languages can become a somewhat religious topic and discussions can become very heated fairly quickly. I therefore came to my personal conclusion that a programming language is not bad or good in itself, it’s just that everybody has a different taste. It’s the same with food: While I hate fish (and I have my reasons why), someone else might love fish (for the same reasons). 

I love Java. To be honest, I actually don’t love Java. It has some downsides that I am well aware of, but I didn’t have the time yet to learn Kotlin. Let’s just say that I prefer Java over other programming languages.

I hate C++. I hate it from the bottom of my heart. I had a C++ course at university and while I learned about pointers, memory management etc, the most important thing that I took away from that course is that I hate C++. I know that it has some advantages and that there are good reasons for it to exist, but that doesn’t mean that I have to use it.

But why do people use C++ in the first place?

The most important advantage that people state about C++ is that it runs on bare metal. You have direct control over the CPU and RAM which means that you can make the most use of it: Instead of copying entire objects and sending them around in memory, you can just use pointers to objects and the only bottleneck of performance is your style of programming.

On the other hand, this is the main reason why I hate C++: For the most part, I don’t care about memory management. I don’t want to think about whether I am passing objects or pointers around, converting objects to pointers and pointers to objects and objects back to pointers. While C++ gives you the possibility to mess with your hardware directly, most people (including me) aren’t good enough at such low-level-programming which results in mistakes, bugs and possibly severe security issues which could be avoided if such low-level work is left to professional computer scientists who have spent their entire lives doing such stuff.

Another thing that I don’t like about C++ is that it’s an old beast which grew over time to a horrible mess of code patches. To see what I mean, you don’t even have to look far. Just look at strings in C++: There is the std:string, but Qt simply introduces its own QString class. Why can’t there be one standard way of handling strings? Then, have a look at exceptions: I know that exceptions are not the holy grail of error handling and there are reasons against exceptions, but in C++, one library uses exceptions, the next one uses error codes and yet other libraries use boolean parameters. Why can’t there be a standard way of exception handling?

I know that Java has similar issues with newer features. In particular, I don’t like the new streams that were introduced in Java 8, but in general, Java learned from what went wrong in C++ and fixed it.

But if Java isn’t perfect either, what do I consider to be perfect? At work, I am using C# and to be honest, I actually do like it. It uses exceptions, but the stupid idea of checked exceptions was removed. I am also a great fan of Properties which remove the need for Accessor methods. Furthermore, Kotlin popped up on the horizon and from what I read and heard, it seems to be wonderful: No more NullPointerExceptions thanks to null safety! Unfortunately, I didn’t yet have the time to learn it properly, but its’s something that I definitely want to do.

Of course, there are many more programming languages which try to solve the mess left behind by C++, Java and alike. For instance, a friend of mine is a big fan of Golang. He loves it because code is so straightforward and unnecessary keywords are simply left out. And I hate it for just that reason: How on earth should I know that a method whose name starts with an uppercase letter is implicitly public and methods starting with a lowercase letter are private? Why can’t there be that one simple keyword in front of the method name which makes code so much easier to read?

Again, this is all my personal preference and I understand that there are people who have different opinions, but that’s just my taste, you might think differently. Thanks for listening 🙂

Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.