* Re: [gentoo-dev] Re: estack_{push,pop}: cool new helpers or over engineering?
@ 2011-12-16 23:20 99% ` Mike Frysinger
0 siblings, 0 replies; 1+ results
From: Mike Frysinger @ 2011-12-16 23:20 UTC (permalink / raw
To: gentoo-dev
[-- Attachment #1: Type: Text/Plain, Size: 1933 bytes --]
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
[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
^ permalink raw reply [relevance 99%]
Results 1-1 of 1 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2011-12-14 22:25 [gentoo-dev] estack_{push,pop}: cool new helpers or over engineering? Mike Frysinger
2011-12-14 23:49 ` Mike Frysinger
2011-12-16 7:29 ` [gentoo-dev] " Steven J Long
2011-12-16 23:20 99% ` Mike Frysinger
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox