I started off my professional career programming in Java, which wasn’t my preferred language, but as there is a lot more demand for it there are more jobs available and thus it made sense I ended up programming in it. Nevertheless I have always felt the urge to program using C++ some more, and in my latest job switch I did make the switch from Java to C++, but not all was rainbows and sunshine. It seems that my idea of what C++ was has been distorted over the years and Java has grown on me a lot more then I was aware of.
When reading data from a file multiple times, there are basically two main ways to do so. You can either always reopen the file or you can keep the file open and jump to a specific location. With the option to jump to a specific location inside the file, I was wondering exactly how much faster it is to use this function over re-opening the file every time.
Initially my question was more why would anyone re-open a file when C++ offers a way to reset the file pointer to the beginning of the file? In my mind there is no way that the latter could be any faster, and since both have the same effect why ever bother? But of course I had to put my idea to the test.
I always believed that using a primitive type, or native array would be more performant compared to using a vector. However, the C++ standard book says that you should always use a vector. This sounds odd to me as why would you use a dynamic length variable if you want to have a fixed size list? The big problem with C++ (or actually C) arrays is that it has no built-in length like Java has. However there also exists a standard array class, which seems to fill this gap. So it is time to see how these three different options perform.
In my previous blog post, we noticed that concatenating strings was a mixed story depending on whether it were all real strings, or if you were mixing strings with integers and doubles. To understand the full picture we need to investigate how much of a penalty was taken because of the different way to convert the integer or double to a string. In this blog post, we will do exactly that.
In my previous blog post I compared the different ways of concatenating a string in C++. I did however miss one very obvious way to do this. In contrary to Java (where a String is immutable), C++ just offers an append method on a string. In this short blog post I repeat the previous test but now include the append method from string.
String concatenation is a very common operation to be done. From my time with Java, I have been warned many times that naive string concatenation could destroy the performance of your application. This is because the system has to create a lot of in-between strings, causing many copy operations to be executed. Instead you should use the provided StringBuilder.
Now that I came across a similar situation in C++, I was wondering whether the same is true here. In this blog post I will compare three different ways to concatenate a string. But I will go the extra mile as well, and see how combining strings and numbers has an effect on the concatenation.
Although I spent my first years at University programming in C++ and only later switched to Java, it seems that because I started my professional career with Java, it has formed my coding style a lot more than I expected. As I am writing production code using C++ now, I see quite a lot of differences in coding style and I even feel that the way I syntactically structure my code simply doesn’t feel right with C++.
There are a lot of similarities between Java and C++, they both are Object Oriented programming languages and such you create classes with methods and members. Each of these need to have a decent name, which is language independent, as a name should be short and expressive at the same time. However, I tend to write more verbose C++ code compared to Java. In this blog post we will examine the cause of this and how you can deal with it.