coding style for who.c

Glenn L. McGrath bug1 at ihug.co.nz
Sat Mar 11 20:48:37 UTC 2006


On Sat, 11 Mar 2006 10:50:42 -0800
Devin Bayer <devin at freeshell.org> wrote:

> In addition, I dislike having to make
> 	if(a = strchr(str,'-'));
> into
> 	if((a = strchr(str,'-')));

IMHO this is bad coding style, you shouldnt put assignment operators in
conditions without good reason.

Why not do

a = strchr(str,'-');
if (a) {
}

A good reason to put an assignment in a condition is when your testing
its result for a loop, for example

while ((a = strchr(str,'-'))) {
	/* do something with a */
}

or if you want to break up the brackets you can always do
while ((a = strchr(str,'-')) != NULL) {

But, i do see a reason to put assignments in if conditions.


Reducing the line count doesnt make the code more readable.


I prefer to put bracers with single line statements, its good for
consistency, and for same reason as the style guide states.


Glenn



More information about the busybox mailing list