List Archive: gentoo-dev
On 19:22 Tue 31 Mar , Ciaran McCreesh wrote:
> On Tue, 31 Mar 2009 11:05:30 -0700
> Donnie Berkholz <dberkholz@g.o> 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.
Thanks for your valuable contribution of sarcasm. It's guaranteed to
give everyone a happy day.
--
Thanks,
Donnie
Donnie Berkholz
Developer, Gentoo Linux
Blog: http://dberkholz.wordpress.com
|
|