Archive

Archive for the ‘Coding Style’ Category

Code reviews

August 22nd, 2008

I’ve worked at companies that existed at both extremes of the spectrum on this issue. Most companies do not perform code reviews. However, a few do. I’m indifferent on it’s use (Edit- actually I’m always for code reviews) however I do think it’s very effective for a few reasons:

  • When a programmer modifies code in the domain of a peer. This way, this programmer is not unintentionally breaking something the domain expert has implemented. So say, a game programmer should conduct a code review with the graphics programmer when they tresspass into each other’s domain
  • When the source codebase is locked down. Programmers can send code reviews which can go up the chain to upper management giving them the opportunity to verify if the feature should go into the build.
  • Helps insure coding guidelines are enforced

Those are the main benefits I’ve noticed from integrating applications like CodeReviewer.

Coding Style, Programming

Bools vs Enum

August 15th, 2008

Programming Tip: Use Enums over Bools

You want to use Enums over bools whereever applicable for function arguments. If there is the slightest possibility the argument might ever expand into more then two options, then you want to use an Enum. This way it’s much easier to update code later plus switch statements can be employed which will work towards generating cleaner code.

replace:


void ActiveElevator (bool modeOn)
{
}

with


enum ElevatorModes
{
ElevatorMode_Standby,
ElevatorMode_PowerDown,
ElevatorMode_RaiseUp
} ;
void ActiveElevator (ElevatorMode mode)
{
switch (mode)
.....
}

Coding Style, Programming