Re: [tuxdroid-user] Daemon to USB connection
Status: Beta
Brought to you by:
ks156
From: neimad <ror...@gm...> - 2007-06-08 18:04:47
|
More coding style stuff. This time from commit r357: [...] switch (data[0]) { case TUX_CONNECTION_DISCONNECT: if (disconnect_from_tux() >= 0) result[1] = TUX_CONNECTION_ACK; else result[1] = TUX_CONNECTION_NACK; break; case TUX_CONNECTION_CONNECT: { union_uint16_t id; id.b[1] = data[1]; id.b[0] = data[2]; printf("coucou\n"); if (connect_to_tux(id.w) >= 0) result[1] = TUX_CONNECTION_ACK; else result[1] = TUX_CONNECTION_NACK; break; } case TUX_CONNECTION_ID_REQUEST: [...] I can't agree with the block indentation in TUX_CONNECTION_CONNECT: the curly braces are at the same depth as the switch's braces, which is badly readable. I'd indent it as follows: [...] switch (data[0]) { case TUX_CONNECTION_DISCONNECT: if (disconnect_from_tux() >= 0) result[1] = TUX_CONNECTION_ACK; else result[1] = TUX_CONNECTION_NACK; break; case TUX_CONNECTION_CONNECT: { union_uint16_t id; id.b[1] = data[1]; id.b[0] = data[2]; printf("coucou\n"); if (connect_to_tux(id.w) >= 0) result[1] = TUX_CONNECTION_ACK; else result[1] = TUX_CONNECTION_NACK; } break; case TUX_CONNECTION_ID_REQUEST: [...] (Note that I also spaced things out, most notably the variable declaration, but that's another topic ;-)) The block is a sub-block of the switch()'s block and as such must be indented. Yes, as a consequence the code within this case is indented one depth level more than the code in other, block-less cases, but that's a small price to pay for increased readability. I also moved the closing brace *before* the break, as in my view all the code in a case should appear before the break (unless, of course there are several places where break appears) just like in the block-less cases. This last point is debatable, but I think the indentation level should *really* be as I pointed out above :-) Damien, coding-style integrist |