coding style for who.c
Devin Bayer
devin at freeshell.org
Sat Mar 11 21:33:45 UTC 2006
On Mar 11, 2006, at 12:48, Glenn L. McGrath wrote:
> Reducing the line count doesn't make the code more readable.
I think this is the main place most style guides go wrong; they focus
on understanding of the little picture instead of the big picture.
Line count it very important. That's why we don't quote entire emails
when responding. If you can't see the start and end of a function all
at once then you have to remember what isn't on the screen.
For your example:
> a = strchr(str,'-');
> if (a) {
> }
I think it totally depends on the usage. If a is used later in the
function, do it this way. But if it's only used in the if'ed block,
it's visual scope is wrong. Looking at this function as a whole
doesn't clearly show the point of a when it's assigned before the if-
block.
int function(char *str)
{
int somevar, more;
char *a;
type_t more;
// do something
for(somevar = 9; somevar % 8; ++somevar) {
printf("%c", str[somevar]);
}
if(a = strchr(str, '-')) {
puts(a);
return 0;
}
a = strchr(str, '-');
if(a) {
puts(a);
return 0;
}
// do something else
for(more = 4; more * 15 % 8; ++more) {
printf("%c", str[more]);
}
return 1;
}
More information about the busybox
mailing list