Why I so often come to realize I hate C++ and still use it

It will be a story.

Yesterday at work I submitted a little patch for review. It was a simple improvement: I removed std::vector of pairs that was manually sorted right after construction and accessed via std::lower_bound, with a boost::containers::flatmap. It's simple, you got the idea, right?

The diff was extremely simple and obvious, but there was a teeny-tine drawback: the original vector stored not standard pairs, but custom structures. And there was a perfect reason for it: these pairs were substitution rules. The definition looked like that: struct Rule { std::string source; std::string destination; }. (OK, it was full of ugly prefixes, because as any other company we have a lot of bullshit in our code style guide, but essentially it was the same.)

Anyway, my colleague looked at this diff and first thing he saw was not the replacement std::vector => boost::containers::flatmap, but the fact that I removed this Rule structure. So he immediately commented: "What was wrong with the original structure?"

I have to admit, I answered very quickly and without hesitation. I wrote something like this: hey, just look below, I replaced vector with flatmap, that's why there is no more Rule, but std::pair instead.

But later I realized that I was being like this PHP-guy who can give a "perfect explanation" why the string "00-00-0000" is parsed to 1st of January 1979 (or whatever it was, I don't remember the joke exactly). The point is that my brain is so damaged by C++ that it took me whole day to understand that his question is perfectly valid, while my answer is total BS.

There is no reason whatsoever why I can't (or shouldn't) store our original Rule structure inside boost flatmap! Any explanation is just another way of saying: yeah, sorry, it's C++, you can't do anything with it.

But if you consider yourself a hacker, you don't give up on problems, you try to solve them. And it doesn't matter if the problem ain't worth shit, you can't sleep well unless you find a way.

Well, in this case it was not hard at all. As Woody Allen once said, be original, but when you have to steal, steal from the best. Lots of good people (not those OOP-brain-washed fuckers) who came to C++ by mistake or are forced to use it because that's where the money is, already write generic code for ages. Look at boost::geometry. The authors don't make assumptions about how you store your geometries. They don't imply you store point as boost::geometry::point or whatever. No, you are free, as you should be, to choose yourself what you think the best structure for you geometries is.

So, the solution is simple: just rewrite half of STL to make it work with concept "pair". Allow users to define their own access methods as specializations for std::pair_traits... blah-blah-blah. You got it.

If you don't feel pity for me already, you will once you know I actually couldn't sleep well that night.

And then, I actually started to write code that would solve this problem (you still remember what the problem was, right?).

I wrote something like "namespace std { template<typename Key, Value> pair_traits { const Key &first_get..." and said to myself: oh my God!!! Really? Is that what I think how beautiful code should look like?

So, my personal problem with C++ is that I know it quite well and I probably can find solution to any problem and feel happy about it like a child, but in the end the code will be so fucking ugly, that I will never be proud of it. The best I will be able to say is "look how well I know C++" to people who want to hire me. But with friends, I will always be saying: C++ is crap, the best language is Z-talk, which I'm developing (for how many years now?), just wait a bit.

Yeah, sad story.