Gentoo Archives: gentoo-dev

From: Donnie Berkholz <dberkholz@g.o>
To: gentoo-dev@l.g.o
Subject: Re: [gentoo-dev] Small review on function return codes and simplicity
Date: Tue, 31 Mar 2009 18:28:28
Message-Id: 20090331182825.GH13746@128-193-143-54
In Reply to: Re: [gentoo-dev] Small review on function return codes and simplicity by Ciaran McCreesh
1 On 19:22 Tue 31 Mar , Ciaran McCreesh wrote:
2 > On Tue, 31 Mar 2009 11:05:30 -0700
3 > Donnie Berkholz <dberkholz@g.o> wrote:
4 > > I noticed some eclass commits using java-pkg_func-exists() and it's a
5 > > lot more complicated than it needs to me. Perhaps not everybody knows
6 > > that bash generally gives a return status from functions of the last
7 > > command run in that function. So these two things are equivalent:
8 > [...]
9 > > java-pkg_func-exists() {
10 > > [[ -n "$(declare -f ${1})" ]]
11 > > }
12 >
13 > What's with that -n thing? If you're going for less complicated, you
14 > might as well go the whole hog:
15 >
16 > java-pkg_func-exists() {
17 > declare -f ${1} >/dev/null
18 > }
19 >
20 > But then you're wasting time writing all those extra bytes
21 > to /dev/null, so:
22 >
23 > java-pkg_func-exists() {
24 > declare -F ${1} >/dev/null
25 > }
26 >
27 > But wait! $1 and ${1} are the same when they're surrounded by
28 > whitespace. Those bytes are important!
29 >
30 > java-pkg_func-exists() {
31 > declare -F $1 >/dev/null
32 > }
33 >
34 > And we don't need that extra space before the >, either:
35 >
36 > java-pkg_func-exists() {
37 > declare -F $1>/dev/null
38 > }
39 >
40 > I hope people can apply these lessons to write much more compact code.
41 > I'm sure we all agree that shorter code is always better, since having
42 > less to read makes things easier to understand.
43
44 Thanks for your valuable contribution of sarcasm. It's guaranteed to
45 give everyone a happy day.
46
47 --
48 Thanks,
49 Donnie
50
51 Donnie Berkholz
52 Developer, Gentoo Linux
53 Blog: http://dberkholz.wordpress.com