1 |
Mike Frysinger wrote: |
2 |
|
3 |
> relying on an external program |
4 |
|
5 |
The point is that external programs can have all sorts of undesired |
6 |
side effects. For instance, if an directory is not readable (or |
7 |
readable but not executable or is on $FILESYSTEM with who-knows-what |
8 |
permissions or accessability problems) it can cause unexpected |
9 |
errors which otherwise are treated by "standard" shell behavior: |
10 |
*This* is why the ls is hackish here, not the readability. |
11 |
|
12 |
About the readability, one can always have different opinions, |
13 |
but your attack is inappropriate: |
14 |
|
15 |
> to get a single line of readable code is better than |
16 |
> multiple lines of code that attempt to do the same thing. |
17 |
|
18 |
First, my suggestions are not "multiple lines" but only |
19 |
exactly *two* lines (i.e. only one additional line): |
20 |
Please compare |
21 |
|
22 |
set -- "${ROOT}"/etc/openvpn/*/local.conf |
23 |
if test -e "${1}" |
24 |
|
25 |
with the "single line of readable code" which contains not less code, |
26 |
but is only squashed into one line: |
27 |
|
28 |
if [[ -e $(ls -1 -- "${ROOT}"/etc/openvpn/*/local.conf) ]] |
29 |
|
30 |
Is this really so much more readable? |
31 |
(The "--" can be omitted in both code pieces iff portage has a test |
32 |
that ROOT does not start with "-"). |
33 |
|
34 |
And if you really want only readability, you should like even much |
35 |
more my second suggestion which could also be squashed as two lines: |
36 |
|
37 |
Exists() { test -e "${1}"; } |
38 |
if Exists "${ROOT}"/etc/openvpn/*/local.conf |
39 |
|
40 |
I would say this is *way* more readable than the complex 1-liner. |
41 |
Of course, opinions may differ, but I think an unfounded attack as |
42 |
|
43 |
> your further examples here are even worse on many levels. |
44 |
|
45 |
is not appropriate here. |
46 |
|
47 |
Regards |
48 |
Martin |