Game Development Reference
In-Depth Information
Bracing
Bracing is one of those things I do feel strongly about. I have fixed actual logic bugs
due to poor bracing on more than one occasion. There are three styles I
'
ve run into
in the past. The first is lining up all the braces:
void FindObject (unsigned int id, std::list& found)
{
for (int i = 0; i < m_max; ++i)
{
if (m_map[i].id == id)
{
found.push_back(m_map[i]);
GCC_LOG(
Objects
,
Found
);
}
else
{
GCC_LOG(
Objects
,
Not Found
);
}
}
GCC_LOG(
Objects
,
Next
);
}
The second is called K&R bracing:
void FindObject (unsigned int id, std::list& found) {
for (int i = 0; i < m_max; ++i) {
if (m_map[i].id == id) {
found.push_back(m_map[i]);
GCC_LOG(
Objects
,
Found
);
}
else {
GCC_LOG(
Objects
,
Not Found
);
}
}
GCC_LOG(
Objects
,
Next
);
}
The third is just arbitrarily placing braces where they make sense at the time:
void FindObject (unsigned int id, std::list& found)
{
for (int i = 0; i < m_max; ++i)
{
if (m_map[i].id == id)
{
 
 
Search WWH ::




Custom Search