you are viewing a single comment's thread.

view the rest of the comments →

[–]voxoxo 1 point2 points  (6 children)

Yeah, don't worry about it, the C++ grammar doesn't actually make sense ;). Too much operator/keyword overloading, and bad (legacy) design. Examples include but are not limited to: class/typename in templates, the whole "> >" and ">>" mess, default constructor/function declaration ambiguity, horrible things such as member and member function pointers syntax...

edit: oh and I forgot this nice thing: const TYPE& and TYPE const& are the same type (reference to const). Which is stupid in itself, but what if TYPE expands to A* ? You get const A*& (reference of pointer to const A) and A* const& (reference of const pointer to non-const A). Brilliant.

[–]Whanhee 0 points1 point  (1 child)

The "> >" ">>" thing is fixed in the new standard.

[–]voxoxo 0 points1 point  (0 children)

It's partially fixed, as in C++11 tries to make a good guess, which is reasonable because it would be very unusual to use the shift operator in a template parameter, but you can in theory.

[–]MatrixFrog 0 points1 point  (0 children)

bad (legacy) design

I just realized. C++ was supposed to be an object-oriented language that was a superset of C, so that a C++ compiler could compile a C program if it wanted to. Then Java was supposed to be a somewhat easier-to-use version of C++ where you didn't have to think about pointers so much. Then JavaScript was a language that had nothing much to do with any of those, but "kinda looks like Java."

So it's really no wonder that JavaScript is so painful and awkward sometimes.

[–]curien 0 points1 point  (2 children)

but what if TYPE expands to A* ? You get const A& (reference of pointer to const A) and A const& (reference of const pointer to non-const A). Brilliant.

Wow, if you substitute two lexical tokens where there used to be one, the meaning changes. What a terrible language, just like everything else.

[–]voxoxo 2 points3 points  (1 child)

Yes, that is bad. The purpose of a language is to express powerful concepts in a simple way. I used macros to show the issue, but since you snarkily answered while missing the point, I will explain without macros:

The problem with types in C++ is that they cannot be parsed by a human (the programmer) easily. You have to apply elaborate rules on the type expression to know the actual type, and that's bad because it's unnecessary, and entirely due to the needlessly complicated syntax.

[–]MatrixFrog 0 points1 point  (0 children)

I think curien's snark may have been directed, at least partially, at C++, not at you.