On Tue, 31 Mar 2009 11:05:30 -0700 Donnie Berkholz <dberkh...@gentoo.org> wrote: > I noticed some eclass commits using java-pkg_func-exists() and it's a > lot more complicated than it needs to me. Perhaps not everybody knows > that bash generally gives a return status from functions of the last > command run in that function. So these two things are equivalent: [...] > java-pkg_func-exists() { > [[ -n "$(declare -f ${1})" ]] > }
What's with that -n thing? If you're going for less complicated, you might as well go the whole hog: java-pkg_func-exists() { declare -f ${1} >/dev/null } But then you're wasting time writing all those extra bytes to /dev/null, so: java-pkg_func-exists() { declare -F ${1} >/dev/null } But wait! $1 and ${1} are the same when they're surrounded by whitespace. Those bytes are important! java-pkg_func-exists() { declare -F $1 >/dev/null } And we don't need that extra space before the >, either: java-pkg_func-exists() { declare -F $1>/dev/null } I hope people can apply these lessons to write much more compact code. I'm sure we all agree that shorter code is always better, since having less to read makes things easier to understand. -- Ciaran McCreesh
signature.asc
Description: PGP signature