News for hackers. Stuff that matters.
Re:C++ in Coders at Work by jacquesm on Friday October 16, 2009 @02:00PM (#885848)
Most of that is 'plain good sense' in any environment, here are a couple that target specific C++ pitfalls:

- Only very rarely is multiple implementation inheritance actually useful. We allow multiple inheritance only when at most one of the base classes has an implementation; all other base classes must be pure interface classes tagged with the Interface suffix.

- Do not overload operators except in rare, special circumstances.

- Make all data members private, and provide access to them through accessor functions as needed. Typically a variable would be called foo_ and the accessor function foo(). You may also want a mutator function set_foo().

- All parameters passed by reference must be labeled const.

- Do not use function overloading to simulate default function parameters.

- We do not allow variable-length arrays or alloca().

- Be very cautious with macros. Prefer inline functions, enums, and const variables to macros.

The only thing that struck me when reading this that I do different is the use of ++p, I would avoid that at all costs.

Pre-increment is a great way to confuse people. I can see why they would use it though, another similar source of confusion (stemming from C really) is the difference between

    *p++ 
and

    (*p)++;
Re:C++ in Coders at Work by coliveira on Friday October 16, 2009 @02:38PM (#885925)
When working with objects you should always do ++p instead of p++. The later one creates a temporary, so you have to work extra hard for nothing.
Re:C++ in Coders at Work by jacquesm on Friday October 16, 2009 @02:45PM (#885937)
That's an interesting one, I never even thought of that! Thanks.
Re:C++ in Coders at Work by philwelch on Friday October 16, 2009 @03:27PM (#886011)
Hence the old joke that C++ should really have been called ++C because "C++" violates good C++ practice.