C++ Converting Integer/Double To String

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.

Continue reading

Advertisements

C++ String Concatenation Appendix

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.

Continue reading

C++ String Concatenation

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.

Continue reading

C++ Coding Style

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.

Continue reading

C++ Float vs Double

Since I am no working with C++ and no longer use Java as my mainly programming language, I was wondering whether some of the past experiments would yield different results. In this blog post I will repeat the exercise of comparing floats and doubles but now for C++. Given that Java and C++ do handle types differently it is possible that the results may vary, however both languages implement floating points numbers in the same way, according to the IEEE standard.

Continue reading

C++ Pointers And Constant Object

One of my biggest remarks when working with Java the past few years was the lack of a strict immutability concept. The most you can do is declare your object to be final, which only prevents changing the object being pointed to and not any changes made to the object itself. I remembered that C++ offered a lot more opportunities for this and you could go crazy with the ‘const’ keyword.

However, during some quick investigation regarding this constant behaviour for the GroceriesInsight project, I discovered that I was a bit off with how C++ handles the constant behaviour of arguments passed to a function.

Continue reading

ObjectSavingFramework – Initial Version

As it goes with all software, initially you think you have it all figured out and it’s all clear, but as soon as you start writing it you realise there are a couple of things not as straight-forward as you would have liked. The implementation of the ObjectSavingFramework is no exception to this, even though it was designed to be a very simple application.

The first version only had to have 3 different concepts:

  • Objects: which contains other elements (potentially other objects).
  • Values: which just indicate a certain value.
  • References: pointers to objects.

The references are an important aspect to avoid infinite nesting, or object duplication. An object that contains another object will have to decide whether this object is private to him, or if it is shared. If it is a private object, the whole object needs to be written as a child element, if it is shared then the reference is required. It is however this reference concept that caused most of the problems.

Continue reading