|
|
|
|
|
by mrgriffin
2453 days ago
|
|
I don't write brackets where the condition and body fit on one line, and do otherwise. e.g. like these: if (ptr == NULL) return NULL;
for (int i = 0; i < n; ++i) dst[i] = src[i];
I particularly like it for guards at the beginning of a function, because they end up being less visually heavy, thus drawing my attention to the (presumably more business-logic-y) other lines of code.It's somewhat like how Ruby lets you write your control structure at the end of a statement to have it only apply to that statement, e.g. return nil if ptr.nil?
And I find this style looks different enough to multiple statement control structures that I don't make the mistake of adding an additional statement without also adding brackets.Of course this is a comment about formatting code, so YMMV. |
|