Sunday, July 21, 2024

C++ horrible aspects

C++ horrible aspects

 Linus Torvalds described C++ as being a horrible language. While C++ has its dark corners I choose it any day over any other language. There are some horrible aspects though: 

  • rvalue references becoming lvalue references. Not sure who invented this but he should be banned from the committee
  • universal references and perfect forwarding. Again a very confusing idea to reuse the rvalue reference. The reference collapsing rules doesn't make it easier either
  • two phase lookup. Confusing rule which could have been solved by stating that a template is only used at instantiation time. No more need for typename or make code (non) dependent
  • lack of uniformity in STL. For example there is reset and clear.
  • functional programming style over object oriented. Why not make the regex functions member functions? This will help intellisense which is an important aspect for programming these days.

Monday, June 24, 2024

Careful with that initializer_list part 2

initializer_list

 When using Boost.JSON I stumbled upon the following issue:

boost::json::value jv(1);  // creates a number type
boost::json::value jv{1};  // creates an array type

 The value object is something like this:

struct Value
{
   Value(int);
   Value(double);
   Value(std::initializer_list<int>);
};

 This gives the following invocations:

Value vl1(1);  // invokes Value(int) constructor
Value vl2{1};  // invokes Value(std::initializer_list<int>); constructor

 This is a know issue in C++. A programming language should be unambiguously be interpretable and the C++ had decided that in such case the initializer_list has precedence. Not sure if that's a good solution since the ambiguity may only appear when running under the debugger or at customer site. Personally I would require that double braces are used but the C++ committee has decided otherwise. The uniform initialization problem is still not solved.

 

C++ horrible aspects

C++ horrible aspects  Linus Torvalds described C++ as being a horrible language. While C++ has its dark corners I choose it any day ove...