Mikademus wrote:There is often an interesting tension between a language's programmability and its readability: languages that are natural-semantic to read also may tend to be arduous to write and may impose restrictions on how solutions can be expressed in code. C++ tends to side with flexibility over readability. I fully endorse this, but then I have the fluency of 20 years experience with it now, nonetheless I can still remember all the pitfalls of learning it. O.o C++ is an expert-friendly language, but unfortunately the discipline and foresight required by these experts to produce maintainable code aren't very common resources. This is not the language's fault though.

You are 13 years my senior, so I can respect that view point. I still feel that the standard, in this case, results in a negative ROI. Here is why: this semantic-shortcut allows one to define a combination of variables of type, const-type, pointer/reference-to-type, const-pointer-to-type, pointer/reference-to-const-type, and const-pointer-to-const-type. I cannot recall a single instance when this flexibility has ever been useful. The only time I can even recall seeing this flexibility used was in an educational setting. Under what circumstances or in what context is this ever useful? I do not think it is unreasonable of me to propose that this shortcut introduces unnecessary confusion to learning the language, to reading the language, and to understanding the language. And the trade-off is for, maybe, 1% of cases? This is of course in my experience, and I only have 7 years of c++ (~15y of "programming"). Two of my favorite ideologies come to mind:
Antoine de Saint Exupéry wrote:In anything at all, perfection is finally attained not when there is no longer anything to add, but when there is no longer anything to take away.
Obviously the language should be extended to allow programmers to solve more problems, or to solve existing problems in an easier fashion. My point with this is that in my experience only one solution is necessary, and often times the best solution is also the simplest solution. And that we should strive for simplicity.
Isaac Asimov wrote:Two is an impossible number, and can't exist. (this also known as the "zero, one, or infinity" rule.)
I know this is not 100% representative, since these are not the same type, they are however all bound to the same type. The premise here being, if you are using a type, const-type, pointer/reference-to-type, const-pointer-to-type, pointer/reference-to-const-type, or const-pointer-to-const-type, in what context do you ever need to use more than one of these definitions? In my experience rarely, if ever. I assume this to be the general case.
I'm thinking that using classes to contain enums might force some run-time overhead. Enums are compile-time constants, but (pure container) classes are instantiated on the stack. I don't know it an optimising compiler will elide this for classes only consisting of static or compile-time constant members. Also the semantic message sent by using a class as a namespace might be surprising when browing the code in that one expects classes to do more than just prefix enum names. These both points are just nit-picking and speculative though, and I realised I do use your style of enums-in-classes quite frequently, but usually in conjunction with storing the enum value(s), f.i. for representing settings or for serialisation.
Enums being compiler constants, I would assume compilers these days are clever enough to treat them as such even if they are defined within a class. It would be awkward, I think, since the compiler would likely have to write this exception into the compiler - and there would be no need to do so. Of course, I have not actually verified this. I also often use Enums in classes in conjunction with class members for setting/flag storage.
As for semantics, note that c++0x uses "enum class Name : type {}" syntax. It does seem awkward, even here. I am not sure why they decided to use "class" instead of "typename" here. Or maybe they will allow typename and class to be interchangeable, as they do in template declarations? I think the typename/class swap case is an even worse ROI than type specifiers. The allowance of two keywords for the same purpose is just silly. In both cases, the "typename" keyword conforms more to natural-language semantics.
Definitely so! I'm very excited about it, and it will address a number of nagging kinks in the language! I'm a bit disappointed with that the Standard Committee had to cut out 'concepts' though, apparently for political reasons? My personal most-highly-anticipated features are the "auto" keyword and template aliases!...and Lambda Expressions! Hot damn, how could I forget that we finally get closures in C++!!!
Indeed
