# Learning C++ - The Bullshit (Part 1)

So I’m learning C++ at university now. First I thought, yay, another programming language for my portfolio. But now I think “Oh shit, I won’t pass my exam”. Why? I want to cover the topic in a short series of articles. And, as the title suggests, I will tell you why I hate C++.

When we started C++, I already knew C (which is the “basis” of C++, but huh - C++ isn’t C at all), Java (which is close, but better [IMHO]), Ruby (of course) and Bash (just for completeness). I already wrote Python, Haskell, Lua and some other languages. So - I’m not unexperienced in this field!

Please note: I’m still learning C++ and I’m of course not an expert. This article is a rant on the stuff I don’t understand or on stuff where I don’t get why it’s so complicated.

# Declaration vs. Definition

When talking about declarations and definitions a C programmer thinks about header files and source files. But from what I understood in the lessons, this does not apply for C++ at all. You can mix them up fairly easily. At least that’s my feelings. Of course, you also have to write sooo much stuff. Lets write a header for a simple 2D vector:

class Vector2D
{
int x;
int y;
/* or shall we put this into the definitio? I don't know! */
public:
Vector2D(); /* constructor */
/* some ugly operator overloading, I will rant on this later on */
std::string to_string(void);
Vector2D * reverse(void);
}


Now, that’s your prototype. And now, you can rewrite the whole stuff. Don’t much you say? Now, take a class with 100+ Methods and additional operator overloadings. We’ll reach 500 lines really fast (pure code, no comments) without implementing a single line of code with it!

The fact that you can define methods for a class in two ways is also very disturbing to me:

Vector2D *
Vector2D::reverse(void)
{
}

/* vs. */

class Vector2D
{
Vector2D *
reverse(void)
{
}
/* more stuff */ <br />
};


What the fucking hell is that?

The java compiler is intelligent enough to use the definition of the class. Now you argue about interfaces? You need headers with the class declaration for interfacing to a binary or something? Ok then, but I would bet there is a way to do this in a much cleaner way. Not because Java does this, I know that Java and C++ differ because of the Java VM. You can do reflection on the JVM which you can’t do that easy with C++.

But I’m talking of syntax! Why can’t we just say “Hey, there is the header, the information for return types and everything is there - we don’t need it in the definition!” or something like this? Why do we have to write that much code for almost nothing?

# I’m a friend!

What’s this friend keyword about? What the fucking hell is it about? We don’t need this shit! Of course, this is about operator overloading, but I won’t cover that topic in this article but in the next one.

Lets think of another language which supports operator overloading? How do they do it? Lets think about Ruby for example. You can overload an operator in Ruby. And Ruby doesn’t have this keyword or something comparable. Why? Because the syntax of Ruby is meant to be as clean as possible. And C++ is not. That’s it. This has nothing to do with implementation related things, the whole topic is only about Syntax. And the C++ guys just produced shit.

# Reference vs. Pointer

What is this:

CustomType & new_customtype(int input);


An allocator function for the CustomType type you say? Well, now what is

CustomType * new_customtype(int input);


this? The same? Exactly! There is no difference, because both of these functions return a pointer to a new allocated object. The reference thing is just a garbled pointer. So why do we need it? Exactly: We don’t fucking need it! But if you don’t need it, C++ supports it! For sure!

That were just some of the points I already hate at C++.

To be continued…