coding style for who.c
Devin Bayer
devin at freeshell.org
Sat Mar 11 18:50:42 UTC 2006
On Mar 11, 2006, at 10:24, Rob Landley wrote:
>> The second patch fixes the coding style with no changes to the
>> binary.
>
> Changing spaces to tabs is cool. Why the extra curly brackets
> around single
> line ifs? (I haven't rejected this one, I'm just asking if there's a
> rationale here. Seems an aesthetic choice.)
Maybe because that's what the busybox coding style guide suggests.
The rational seems to be "because this isn't python", but python was
designed to look clear. Extraneous curly braces and parentheses just
clutter up the code. Since you seem to agree, perhaps an amendment
to the style guide (see patch).
In addition, I dislike having to make
if(a = strchr(str,'-'));
into
if((a = strchr(str,'-')));
How can the second one be considered easier to read? To fix this you
need to add -Wno-parentheses to the CPPFLAGS.
Index: style-guide.txt
===================================================================
--- style-guide.txt (revision 14524)
+++ style-guide.txt (working copy)
@@ -550,40 +550,6 @@
applet and put it in the utility.c file instead.
-Brackets Are Your Friends
-~~~~~~~~~~~~~~~~~~~~~~~~~
-
-Please use brackets on all if and else statements, even if it is
only one
-line. Example:
-
- Don't do this:
-
- if (foo)
- stmt1;
- stmt2
- stmt3;
-
- Do this instead:
-
- if (foo) {
- stmt1;
- }
- stmt2
- stmt3;
-
-The "bracketless" approach is error prone because someday you might
add a line
-like this:
-
- if (foo)
- stmt1;
- new_line();
- stmt2
- stmt3;
-
-And the resulting behavior of your program would totally bewilder
you. (Don't
-laugh, it happens to us all.) Remember folks, this is C, not Python.
-
-
Function Declarations
~~~~~~~~~~~~~~~~~~~~~
More information about the busybox
mailing list