• Create Account

### #ActualÁlvaro

Posted 30 November 2012 - 03:38 AM

Although I agree that there are valid uses cases for everything in the language, I mostly restrict myself to the subset of the language that I believe every C++ programmer will understand, because code should be written primarily to be read by other programmers.

Some examples:
• I use inheritance very infrequently. When I do, I only use single public inheritance and only for the purpose of using virtual dispatch, and I always provide a factory function that creates the actual objects (this is also about the only place where I would write new' in a program, which is wrapped in a smart pointer right away). The rest of the code is not allowed to know about the specific subclasses.
• I don't use RTTI.
• I only overload operators when defining mathematical classes, and the occasional operator << or >> for streams.
• I don't use trivial standard algorithms (e.g., std::copy), because loops are much easier to read, especially with C++11.
• I don't make complicated template structures, preferring to do some things at run time that could be done at compile time, because it usually helps the clarity of the program.

I am not as adverse to goto as others are here. I learned programming in the 80s and I wrote my share of goto-packed nightmare programs in BASIC. I don't recommend this to anyone, but it helps me tell the difference between a goto that shows poor understanding of loops and function calls (the vast majority of gotos beginners would use) and one that is clear. There are two types of goto that are so useful and so harmless that they were given special names: break' and continue'. Using goto to break out of a loop from within a switch statement, for instance, seems perfectly fine to me. I'll write the code in some other way if I think it's more clear, but only then.

### #2Álvaro

Posted 30 November 2012 - 03:36 AM

Although I agree that there are valid uses cases for everything in the language, I mostly restrict myself to the subset of the language that I believe every C++ programmer will understand, because code should be written primarily to be read by other programmers.

Some examples:
• I use inheritance very infrequently. When I do, I only use single public inheritance and only for the purpose of using virtual dispatch, and I always provide a factory function that creates the actual objects (this is also about the only place where I would write new' in a program, which is wrapped in a smart pointer right away). The rest of the code is not allowed to know about the specific subclasses.
• I don't use RTTI.
• I only overload operators when defining mathematical classes, and the occasional operator << or >> for streams.
• I don't use trivial standard algorithms (e.g., std::copy), because loops are much easier to read, especially with C++11.
• I don't make complicated template structures, preferring to do some things at run time that could be done at compile time, because it usually helps the clarity of the program.
I am not as adverse to goto as others are here. I learned programming in the 80s and I wrote my share of goto-packed nightmare programs in BASIC. I don't recommend this to anyone, but it helps me tell the difference between a goto that shows poor understanding of loops and function calls (the vast majority of gotos beginners would use) and one that is clear. There are two types of goto that are so useful and so harmless that they were given special names: break' and continue'. Using goto to break out of a loop from within a switch statement, for instance, seems perfectly fine to me. I'll write the code in some other way if I think it's more clear, but only then.

### #1Álvaro

Posted 30 November 2012 - 03:35 AM

Although I agree that there are valid uses cases for everything in the language, I mostly restrict myself to the subset of the language that I believe every C++ programmer will understand, because code should be written primarily to be read by other programmers.

Some examples:
• I use inheritance very infrequently. When I do, I only use single public inheritance and only for the purpose of using virtual dispatch, and I always provide a factory function that creates the actual objects (this is also about the only place where I would write new' in a program). The rest of the code is not allowed to know about the specific subclasses.
• I don't use RTTI.
• I only overload operators when defining mathematical classes, and the occasional operator << or >> for streams.
• I don't use trivial standard algorithms (e.g., std::copy), because loops are much easier to read, especially with C++11.
• I don't make complicated template structures, preferring to do some things at run time that could be done at compile time, because it usually helps the clarity of the program.
I am not as adverse to goto as others are here. I learned programming in the 80s and I wrote my share of goto-packed nightmare programs in BASIC. I don't recommend this to anyone, but it helps me tell the difference between a goto that shows poor understanding of loops and function calls (the vast majority of gotos beginners would use) and one that is clear. There are two types of goto that are so useful and so harmless that they were given special names: break' and `continue'. Using goto to break out of a loop from within a switch statement, for instance, seems perfectly fine to me. I'll write the code in some other way if I think it's more clear, but only then.

PARTNERS