Mike Frysinger wrote: > On Saturday 26 April 2008, Denys Vlasenko wrote: >> On Saturday 26 April 2008 05:26, Mike Frysinger wrote: >>>> > [ -n "$var" ] is clear. [ "$var" ] is not. >>>> >>>> it's exactly analogous to "if (foo != 0)" vs. "if (foo)". >>>> >>>> it's all subjective. i'd probably have to look up "-n". :-) >>> i doubt it's the same. most people who understand shell coding know what >>> the -n test means. i would doubt that most people know what the default >>> behavior is if no operator is specified at all. unlike C coders who know >>> that "true" means "non-0". >> http://en.wikipedia.org/wiki/Color_of_the_bikeshed ? > > as i explained, it isnt just subjective, thus this does not apply. my > assertion is that every C coder knows that "if (foo)" and "if (foo != 0)" is > the same thing. shell coding is a much looser art form and a lot less people > know that [ "$foo" ] is the same thing as [ -n "$foo" ]. ive seen people > make [ "$foo" ] explicit, but do it wrong because they didnt really > understand what the implicit behavior was in the first place. and when > quizzed directly, many havent the foggiest. > > if the only people working on the shell code in question were you, myself, > and > a few other people, then yes, [ "$foo" ] is fine because i'm assured we all > know these fugly little details in our head. but we arent the only ones > touching it. > -mike >
It is stating the become philosophy of programming ... not everything that can be done should be done. In the long term the survival of the code will depend not only on it function but also on its clarity (therefore maintainability). i would always prefer (foo != 0) over (foo) since it will make my intentions clear and a forgotten "!" is easily visible. even in a busybox universe where thigh is good you need (easy) understand. and something else i found missing in the discussion is we are talking about *test code*. there is no production environment were i need to stuff everything into a few bits box. just my two cents, wh _______________________________________________ busybox mailing list [email protected] http://busybox.net/cgi-bin/mailman/listinfo/busybox
