Skip to content
 

Why C++ is bad

Time for a rant…

A: Say… do you really need template programming in order to concatenate some strings? or, god forbid, you need to tokenize the std::wstring and have to write a method for that? Of you need a stringBuilder-like functionality?

B: C++0x standard is going to be old before it will be released. Come on guys, I am not even talking about fancy things like closures here. I am tired of not having rvalues. I am tired of not having static constructors. I am tired of non-human-readable errors of template-based metaprogramming. I am just tired of having pointers standing in my way 80% of time.

C: Do you know what takes most time for me when I work in C++? To replicate some functionality I take for granted in managed code like Java or .Net.

Example:

//Error.h

class Error
{
public:
 int code;
 Error(int c){code = c;};
 static const GenericError;
 static const DisplayError;
}

//Error.cpp

static map<int, const Error*> g_errMap;

class add_values_to_map
{
public:
add_values_to_map(map<int, const Error*>& _map, int& code, const Error& err)
  {
  map[code] = &err;
  }
};

static map<int, const Error*> g_errMap;
static const Error::GenericError(-1);
static const add_values_to_map tmp1(-1, Error::GenericError);

int main()
{
  Error* p = find_predefined_err_by_code(-1);
}

You probably noticed that this code replaces a static constructor without actually having one. Quite weird half-baked functor class… but this is the best i could come up with.

I’ll hug you if you give me a better solution.

NOTE1: No, I don’t want to call MyFrameworkInit(). Actually, I don’t have the global init method and I intend to keep it that way.
NOTE2: I don’t want to init static variables on the first call to class XX or YY or ZZ or in the non-static constructor of Error. Why? Because I don’t want to introduce any locks in my code.

Leave a Reply

Spam Protection by WP-SpamFree