Gentoo Logo
Gentoo Spaceship

Installation:
Gentoo Handbook
Installation Docs

Documentation:
Home
Listing
About Gentoo
Philosophy
Social Contract

Resources:
Bug Tracker
Developer List
Discussion Forums
Gentoo BitTorrents
Gentoo Linux Enhancement Proposals
IRC Channels
Mailing Lists
Mirrors
Name and Logo Guidelines
Online Package Database
Security Announcements
Staffing Needs
Supporting Vendors
View our CVS

Graphics:
Logos and themes
Icons
ScreenShots

Miscellaneous Resources:
Gentoo Linux Store
Gentoo-hosted projects
IBM dW/Intel article archive




List Archive: gentoo-dev
Navigation:
Lists: gentoo-dev: < Prev By Thread Next > < Prev By Date Next >
Headers:
To: gentoo-dev@g.o
From: Donnie Berkholz <dberkholz@g.o>
Subject: Re: Small review on function return codes and simplicity
Date: Tue, 31 Mar 2009 11:28:25 -0700
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
Attachment:
pgpRT4A9LFhYr.pgp (PGP signature)
References:
Small review on function return codes and simplicity
-- Donnie Berkholz
Re: Small review on function return codes and simplicity
-- Ciaran McCreesh
Navigation:
Lists: gentoo-dev: < Prev By Thread Next > < Prev By Date Next >
Previous by thread:
Re: Small review on function return codes and simplicity
Next by thread:
Re: Small review on function return codes and simplicity
Previous by date:
Re: Small review on function return codes and simplicity
Next by date:
Re: Small review on function return codes and simplicity


Updated Jun 17, 2009

Donate to support our development efforts.

Gentoo Centric Hosting: vr.org

VR Hosted

Tek Alchemy

Tek Alchemy

SevenL.net

SevenL.net

php|architect

php|architect

Copyright 2001-2007 Gentoo Foundation, Inc. Questions, Comments? Email www@gentoo.org.