Re: [PATCH 2/5] kbuild: fix warning when domainname is not available

From: Felipe Contreras
Date: Tue Sep 15 2009 - 04:38:30 EST


On Mon, Sep 14, 2009 at 4:43 PM, Mike Frysinger <vapier.adi@xxxxxxxxx> wrote:
> On Mon, Sep 14, 2009 at 04:25, Felipe Contreras wrote:
>> On Mon, Sep 14, 2009 at 7:46 AM, Sam Ravnborg wrote:
>>> On Mon, Sep 14, 2009 at 01:04:11AM +0300, Felipe Contreras wrote:
>>>> On Mon, Sep 14, 2009 at 12:58 AM, Mike Frysinger wrote:
>>>> > On Sun, Sep 13, 2009 at 17:42, Felipe Contreras wrote:
>>>> >> On Mon, Sep 14, 2009 at 12:12 AM, Mike Frysinger wrote:
>>>> >>> On Sun, Sep 13, 2009 at 15:38, Felipe Contreras wrote:
>>>> >>>> + Âif $domain; then
>>>> >>>
>>>> >>> is this really correct ? Âi think you meant to use:
>>>> >>> [ -n "$domain" ]
>>>> >>
>>>> >> What is the difference?
>>>> >>
>>>> >> $domain unset
>>>> >> test -n "" -> false
>>>> >> test -> false
>>>> >>
>>>> >> $domain is a valid string
>>>> >> test -n "string" -> true
>>>> >> test "string" -> true
>>>> >
>>>> > except that you didnt invoke `test` anywhere. Âyou're executing the
>>>> > contents of $domain.
>>>>
>>>> Ahh, I'll update it to:
>>>> [ "$domain" ]
>>>
>>> Please use [ -n "$domain" ].
>>> Be explicit about what you do.
>>>
>>> [Likewise in c we never omit "int" just because we can].
>>
>> In fact 'int' is implicit of 'signed int', and 'long' is a shorthand
>> of 'signed long int' and so on. Also, AFAIK 'if (foo)' is preferred
>> over 'if (foo == true)' or 'if (foo != NULL)' and sometimes even 'if
>> (foo >= 0)'.
>>
>> What's the point of going for the explicit form? Make the code less readable?
>
> your argument here is the opposite of reality. Âwhile some of us are
> aware of implicit `test`behavior, not everyone is a shell scripting
> master. Âthey look at [ "$foo" ] and dont immediately get the
> intention. Âor perhaps someone typoed and didnt actually want -n
> semantics. Âadd the whole *3* characters and be done with it.

I consider myself an expert in bash (or at least was some time ago)
and I still need to run 'man bash' in order to see what the hell -n
means. On the other hand, what can [ "$foo" ] be confused with? To me
that can be assumed as: $foo is valid.

In any case, I don't see that idiom being used in the source tree
(which I think is bad), and I see -n being used in some places, so
I'll send a new patch using -n for consistency.

Cheers.

--
Felipe Contreras
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/