Gentoo Archives: gentoo-dev

From: Mike Frysinger <vapier@g.o>
To: gentoo-dev@l.g.o
Subject: Re: [gentoo-dev] Re: estack_{push,pop}: cool new helpers or over engineering?
Date: Fri, 16 Dec 2011 23:21:48
Message-Id: 201112161820.33922.vapier@gentoo.org
In Reply to: [gentoo-dev] Re: estack_{push,pop}: cool new helpers or over engineering? by Steven J Long
On Friday 16 December 2011 02:29:25 Steven J Long wrote:
> Mike Frysinger wrote: > > + [[ $# -eq 0 ]] && die "estack_push: incorrect # of arguments" > > ((..)) is quicker than [[ .. ]] for arithmetic stuff, and usually easier to > grok swiftly.
i'm not used to using this style, so for now i think i'll keep the existing (and it's more common in Gentoo atm, or at least in the code base i sample, ignoring the obvious selection bias). i'll noodle on this though and see if i can't convince myself to start using this and live migrating code in the tree.
> (($#)) || die .. is how this would normally be done.
i think this is a little less clear, but considering some of the [advanced/complicated] bash code i've written elsewhere in Gentoo, maybe that's a specious argument ...
> > eshopts_push() { > > if [[ $1 == -[su] ]] ; then > > - __ESHOPTS_SAVE__[$i]=$(shopt -p) > > + estack_push eshopts "$(shopt -p)" > > [[ $# -eq 0 ]] && return 0 > > I'm not sure how this will ever match, given that $1 has been checked > above? (($#==1)) && return 0 # if that applies (might be a 'bug'.)
the larger idea when i first wrote eshopts_{push,pop} was to not do any arg parsing at all, but then i hit the issue that `shopt` and `set` options are like a venn diagram -- a lot of common stuff, but each also has unique options. so i had to introduce a little arg parsing to make it actually work. and the duplicated/forked code in the sub-branches were kept as similar as possible to (hopefully) make things simpler to read at a glance. but that means sharper eyes notice a code branch which can never be hit as you've highlighted here. as for the $#==1 check at the top, i don't want these helpers to require arguments as it would prevent more creative uses. such as: eshopts_push . ./some-script-from-a-package eshopts_pop but maybe that's not a big deal ... -mike

Attachments

File name MIME type
signature.asc application/pgp-signature