Gentoo Archives: gentoo-dev

From: Duncan <1i5t5.duncan@×××.net>
To: gentoo-dev@l.g.o
Subject: [gentoo-dev] Re: [PATCH eutils] Introduce run_in_build_dir() used in a few ebuilds.
Date: Tue, 15 Jan 2013 03:20:53
Message-Id: pan.2013.01.15.03.20.22@cox.net
In Reply to: Re: [gentoo-dev] [PATCH eutils] Introduce run_in_build_dir() used in a few ebuilds. by Mike Frysinger
1 Mike Frysinger posted on Mon, 14 Jan 2013 17:09:51 -0500 as excerpted:
2
3 >>> + [[ ${BUILD_DIR} ]] || die "${FUNCNAME}: BUILD_DIR not set."
4 >>
5 >> really should use -n there
6 >
7 >> Doesn't matter.
8 >
9 > the point wasn't "will it work". it's more "how easy is it to glance at
10 > code and know what it is doing".
11
12 Indeed. But arguably standalone [[ ${var} ]] tests ARE easier to "know
13 what it doing."
14
15 Consider:
16
17 1) The [[ $var ]] case is exactly one of one. There's no misinterpreting
18 it. Even if you don't know the rule by rote, given that it's a boolean
19 test on a string, there's logically only one way to parse it. No
20 mistakes to make.
21
22 2) By contrast, -n is only one of a whole list of -X style tests, and one
23 must stop and think, "Let's see... Oh, yes, -n was non-null."
24
25 3) The situation in #2 is even worse than it might be due to the
26 standalone alternative, making -n (and -z, #4) far less common than they
27 would be otherwise.
28
29 4) You are arguing the "at a glance" position, but didn't even MENTION
30 the needlessly negated logic of [[ -n $string ]] || ... , which could be
31 rewritten to avoid the || negation as [[ -z $string ]] && ...
32
33 5) [[ ]] is already a bashism while the standalone string test is common
34 shell. Surely you're not arguing that people familiar enough with the
35 [[ ]] || construct to parse it at a glance can't equally capably parse
36 the a standalone string test, given its use in non-bash shell context as
37 well.
38
39 6) If you're arguing for explicit, be consistent, with explicit
40 if/then, test, positive -z instead of negated -n logic... ::
41
42 if test -z "${BUILD_DIR}"; then die "${FUNCTNAME}: BUILD_DIR not set."
43
44
45
46 Obviously the example in #6 is taking it a bit far, but my point is, an
47 explicit (if one-of-many) -z/-n test vs. the standalone (single-case)
48 $string test really is personal preference. You obviously prefer it one
49 way, others (including me) prefer the other... for the very same reason,
50 to us, our preferred way is instantly parsable, while the other way
51 triggers "extra processing".
52
53 As such, IMO, "He who codes, decides." =:^)
54
55 (IIRC I did bring up the same thing, naturally arguing my standalone
56 string test preference, in an earlier eclass proposal thread. However, I
57 believe I explicitly mentioned that I considered it a purely personal
58 style thing and that others had the opposite preference, with to my
59 knowledge no official gentoo coding style position taken on it. Given
60 that I had seen, I think you, bring up the point before, I was hoping
61 someone would post the gentoo style-guide link proving me wrong, if there
62 was one. Given that nobody did so, I still believe it to be "he who
63 codes, decides" territory.)
64
65 --
66 Duncan - List replies preferred. No HTML msgs.
67 "Every nonfree program has a lord, a master --
68 and if you use the program, he is your master." Richard Stallman

Replies