if(foo)
{ // smarter, immediately obvious there's a brace
bar();
I can go either way, but I prefer to always have the braces to make code coverage output more useful. For example, a line like if( foo ) returnfalse; will always appear to be covered but I want to know that the return was taken as part of my unit testing.
@L B,
I don't think the inside of a function counts as a level.
Contrived example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
int CountsSomeValuesForSomeReason(int array[][][], int search, int x, int y, int z)
{
int count;
for (int i = 0; i < x; ++i) {
// This is level 1
for (int j = 0; j < y; ++j) {
// This is level 2
for (int k = 0; k < z; ++k) {
// This is level 3
std::cout << "array[" << i << "][" << j << "][" << k << "] = " << array[i][j][k] << '\n';
if (array[i][j][k] == search)
++count; // Too many levels!
}
}
}
return count;
}
Single-statement stuff obviously doesn't need braces, but when you have a lot of stuff going on it is best to use the first style you mentioned for clarity, otherwise finding matching braces is a NIGHTMARE
I used the third for so long and then I just gave up on it because it was so confusing to try and read
While I of course don't actually know what you want to write, I'd assume there is some logic connected to each map<string,float>. If so, it deserves it's own class, which is already at least one brace level less.
There is no 'logic' attached; it's quite literally just a way for me to have named floats in named groups. It's not for my application's logic, its for user usage.