[prev in list] [next in list] [prev in thread] [next in thread] 

List:       gentoo-dev
Subject:    Re: [gentoo-dev] Re: estack_{push,pop}: cool new helpers or over engineering?
From:       Mike Frysinger <vapier () gentoo ! org>
Date:       2011-12-16 23:20:33
Message-ID: 201112161820.33922.vapier () gentoo ! org
[Download RAW message or body]


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

["signature.asc" (application/pgp-signature)]

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic