From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pigeon.gentoo.org ([208.92.234.80] helo=lists.gentoo.org) by finch.gentoo.org with esmtp (Exim 4.60) (envelope-from ) id 1Rbh63-0006io-VP for garchives@archives.gentoo.org; Fri, 16 Dec 2011 23:21:48 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id AA56421C18F; Fri, 16 Dec 2011 23:21:31 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id D269121C176 for ; Fri, 16 Dec 2011 23:20:33 +0000 (UTC) Received: from vapier.localnet (localhost [127.0.0.1]) by smtp.gentoo.org (Postfix) with ESMTP id 491331B4047 for ; Fri, 16 Dec 2011 23:20:33 +0000 (UTC) From: Mike Frysinger Organization: wh0rd.org To: gentoo-dev@lists.gentoo.org Subject: Re: [gentoo-dev] Re: estack_{push,pop}: cool new helpers or over engineering? Date: Fri, 16 Dec 2011 18:20:33 -0500 User-Agent: KMail/1.13.7 (Linux/3.1.0-atsc; KDE/4.6.5; x86_64; ; ) References: <201112141725.22148.vapier@gentoo.org> <201112141849.50101.vapier@gentoo.org> In-Reply-To: Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-dev@lists.gentoo.org Reply-to: gentoo-dev@lists.gentoo.org MIME-Version: 1.0 Content-Type: multipart/signed; boundary="nextPart2619130.JJmE1e1cnG"; protocol="application/pgp-signature"; micalg=pgp-sha1 Content-Transfer-Encoding: 7bit Message-Id: <201112161820.33922.vapier@gentoo.org> X-Archives-Salt: 3dffb988-2ca1-47db-9a05-4fa8775c9cc7 X-Archives-Hash: 80255c35c45f20556092ea44685b2d96 --nextPart2619130.JJmE1e1cnG Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable On Friday 16 December 2011 02:29:25 Steven J Long wrote: > Mike Frysinger wrote: > > + [[ $# -eq 0 ]] && die "estack_push: incorrect # of arguments" >=20 > ((..)) 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= =20 (and it's more common in Gentoo atm, or at least in the code base i sample,= =20 ignoring the obvious selection bias). i'll noodle on this though and see i= f i=20 can't convince myself to start using this and live migrating code in the tr= ee. > (($#)) || die .. is how this would normally be done. i think this is a little less clear, but considering some of the=20 [advanced/complicated] bash code i've written elsewhere in Gentoo, maybe=20 that's a specious argument ... > > eshopts_push() { > > if [[ $1 =3D=3D -[su] ]] ; then > > - __ESHOPTS_SAVE__[$i]=3D$(shopt -p) > > + estack_push eshopts "$(shopt -p)" > > [[ $# -eq 0 ]] && return 0 >=20 > I'm not sure how this will ever match, given that $1 has been checked > above? (($#=3D=3D1)) && 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= =20 parsing at all, but then i hit the issue that `shopt` and `set` options are= =20 like a venn diagram -- a lot of common stuff, but each also has unique opti= ons. =20 so i had to introduce a little arg parsing to make it actually work. and t= he=20 duplicated/forked code in the sub-branches were kept as similar as possible= to=20 (hopefully) make things simpler to read at a glance. but that means sharpe= r=20 eyes notice a code branch which can never be hit as you've highlighted here. as for the $#=3D=3D1 check at the top, i don't want these helpers to requir= e=20 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 ... =2Dmike --nextPart2619130.JJmE1e1cnG Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part. -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.17 (GNU/Linux) iQIcBAABAgAGBQJO69JBAAoJEEFjO5/oN/WBJbUP/RNNbrwXh353IceP2g+1xM8t T679YfuumlsJzoOgp/7UW/bphid7WS846UgZcC6LSrfiKEMYGJvpHdaT3uGEJU2N Kjgtfv2BpGexnhfRe/SK3ki9mbDFSrFjYAyyModYb+B3Ufd9NK2MLxEkDvTLwoHc zrrGvJCJo1+naQ9YVwsYo1N+tbA7+/igvEAUPpZtjY4+LefD7gQxUImC5X/GNp8s HbeZE5D+skJ1RVTx8IXY/fnR0DlknVvcUSFXqHb2vVjVkL4jgk5a5brSrhkDgoMV p+uzzK9y9CQcGntrZVfiKC0IEwNzo1u6ZlEut6KdgslXqLUUKoHNtNjororv/xzm gGFvBlnjrJKgCadVFkt123PNmStbC29jHOSl/ZBGMpmYQiSkTx+0evBBhUs92GoN cuaalHjKeJPXaZhopCPMDvyR7zilkj1xk8Ghk4Ge4BtO55h3Z41g6eujd/cVAuVv g98PBdlPuktE8tPZaDFQ9UAubk1bFHIB85Yw6rks4SJxzruMfRjEFNuYBxRejHB2 jLaggmglC65YFtLClajQzn8HbaqldKu6+nsnyP2syhztVIoZwGrxWGQMFqIhmW+U y+NC4OZQRGvNU4fcWytVVSAbRX+WYIKs4EQht09YnguegKSisUnf9E9yuhQjOCNo oFWe5+d3rmPP6N4GLN8u =M7tk -----END PGP SIGNATURE----- --nextPart2619130.JJmE1e1cnG--