Strange features in C++ (quick post)

C++ is not Java. The banal truth can be helpful by coding, especially for me, because I tend to think in Java even when I’m coding in C++. “Real Programmer can write Fortran programs in any language” and bad programmers write Java programs in any language. (Do you remember this?) But it is a really really bad pracitce, it makes the mastering of C++ almost impossible.

Suddenly I remembered the advice of Mojo Jojo, who teached the powerpuff girls how to be evil. “In order to be evil you have to look evil. The next step in being evil is being mean.” (Take a look at this.) I decided that I would follow that advice and I would use it to be better C++ programmer. The first step is, that my codes have to look profitient. The next step is, that my codes have to be brilliant. Before the step two I must complete the step one, so first I work on the look. Likely nothing seem more profitient than the using of unique and weird C++ features, so I must know more about them and I must use them all time. Here is a small list about the first three features that I didn’t know earlier.

  1. Using namespaces instead of static classes. If you want to use a collection of related static functions in Java, you will create a class, because almost everything is a class in Java, so you will create something like the “Math” class. In C++, you are allowed to create a static class (more accurate, a class with only static member functions), but it isn’t a good choice, there is a better way to handle static functions in C++. Using namespaces is a better idea. It is the natural way to organize related static functions in C++.
  2. Constructor initialization lists. In Java, we use the explicit assignment operator to set the default values of the variables. (We can use it either at the declaration of the variable or in the constructor.) In C++, there is an other way, we can write an initialization list at the header of the constructor. Look at this. It seems weird and tricky, that’s why I like it.
  3. C++-style variable initialization. In Java, we use the assignment operator to set the default value of a variable, so we write something like int variable = 0;. It works in C++ too, but there is an other way to initialize a variable: int variable(null);. Take a look at this. Rembember, if you want to be a profitient C++ coder, your codes have to look like profitient C++ codes.

I will continue the list later, it’s only a matter of time.


About vrichard86

I'm Richard and I'm an enthusiastic coder. I want to be better and I think a professional journal is a great self improvement tool. Welcome to my blog, to my hq, to my home on the web!
This entry was posted in C++ and tagged , , . Bookmark the permalink.