Re: [PATCH] Replace 'test "${var+set}" = set' with 'test -n "${var+set}"'
Eric Blake <[email protected]>
| Newsgroups | gmane.comp.sysutils.autoconf.patches |
|---|---|
| Organization | Red Hat, Inc. |
| Message-ID | <[email protected]> |
On 04/08/2015 04:25 PM, Eric Blake wrote:
> I can beat it in an amortized way, by doing:
>
> f(){ false;}
> ${var+:} f
Or shorter:
f(){ eval "\${$1+:} [ ]";}
f var
>
> but only after I have at least 4 tests at 10 bytes each making up for
> the 12 bytes spent on the function definition (a longer function body of
> 'return 1;' instead of 'false;' guarantees no $? issue, but I already
> argued that no shell with functions has a false that returns other than
> 1). And while we are likely to have 4 or more instances replaced, my
> hack violates our shell function naming conventions (once we put it in
> the right as_fn_ namespace, direct use of false wins every time), not to
> mention legibility (hiding things in a function has its uses, but this
> does not seem to be one of them).
Here again, a function named 'as_fn_isset var' again loses out to the
more compact direct expansion, but at least this form is quite readable.
Likewise, the fact that it uses eval means that anyone passing a
non-variable name to the function deserves the chaos that ensues.
Of course, we can easily turn this thread into nerd sniping, if we
haven't already :) https://xkcd.com/356/
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
signature.asc
(application/pgp-signature, 604 B)
-----BEGIN PGP SIGNATURE----- Version: GnuPG v2 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJVJnU2AAoJEKeha0olJ0NqnG8IAKJ+V4LXZ46GwbusR6wBvbyh lkDksNFd8NLZIJYtil0+X0AhO20Kjgqr+aD0ADiGhlx7BiuhOGCUUfibRR5kP29t 5q2eCWFvHPvzH7t5d++eUWYxABYjcQbUfISg5H8CkMpdddmTNixFW9t3xAL//3aR pJCm3D+633K8hJaFTm5VSzWjChKRJJIn9l6z24HnWabAf2GPMFqefHz/3aZU7Ea5 /LDx90qz8tsw7ydkWoN6xV+Wy0JUfWJjbekp1YA2dRifowibXB+ky+FLwmAbO0G+ A+0u6/hWA+iy95qldP+neprrwodCPVywf+XIO1neb/JdKjUxbsVw8C5G59RU5w8= =PYXD -----END PGP SIGNATURE-----