Game Development Reference
In-Depth Information
found.push_back(m_map[i]);
GCC_LOG(
Objects
,
Found
);
}
else { GCC_LOG(
Objects
,
Not Found
);
}
}
GCC_LOG(
Objects
,
Next
);
}
Which one is the most readable? In my opinion, the first style is much more readable
than the other two. The second style is preferred by some programmers I know
because it saves space and creates more compact code, and they feel that K&R brac-
ing is just as readable. I strongly disagree with this and have fixed a couple of bugs
due to braces getting out of alignment in K&R bracing. By contrast, I have never
fixed a bug due to bad bracing using the first method. Still, it
s considered to be a
valid style at some companies. The most important thing here is that you never,
ever use the third method. Arbitrarily placing braces and tabs is a sure-fire ticket to
creating incredibly hard-to-read code.
'
5,000 Lines of Pure Horror
During development of Barbie Diaries, there were a number of complaints
about the architecture of the camera code. The original author had left the
company, so once the game shipped, I was tasked with refactoring that
whole system before we started production on the next game. When I
opened up SeCameraMgr.cpp, I was horrified to find that the entire camera
system was a series of nested switch/case statements with completely
arbitrary indentation and bracing. This complete lack of style and
organization made the code pretty much unusable. I spent about an hour
just lining up the braces and tabbing so I could even read the code, much
less refactor it. It took me two weeks to refactor the camera system into
something usable and extendable.
Consistency
Which of these function names is best?
Action* FindBestAction(void);
Action* findBestAction (void);
Action* find_best_action( void );
Honestly, it doesn
s just my opinion. It
makes very little difference how you handle capitalization, whether you put a space
between the identifiers and braces, whether you use underscores, and so on. The key
'
t really matter. I prefer the first one, but that
'
 
 
Search WWH ::




Custom Search