1 |
On Wed, Nov 30, 2016 at 8:35 PM, Mike Gilbert <floppym@g.o> wrote: |
2 |
> On Wed, Nov 30, 2016 at 7:11 AM, konsolebox <konsolebox@×××××.com> wrote: |
3 |
>>>> I also prefer some things this way: |
4 |
>>>> |
5 |
>>>> - Indent the contents of the first `if` block for consistency's sake, |
6 |
>>>> and less confusion. |
7 |
>>> |
8 |
>>> I disagree; indenting the entire eclass is silly and does not really |
9 |
>>> improve readability. Also, this is a very common pattern found in |
10 |
>>> other eclasses. |
11 |
>> |
12 |
>> I prefer following consistency before anything else. And it's just |
13 |
>> uncommon and odd, but it's not silly. Imagine if you use another `if` |
14 |
>> block on the second level where more functions are defined. Would you |
15 |
>> also not indent that? |
16 |
> |
17 |
> That first "if" is a bit of a special case; it's only there to prevent |
18 |
> the code from being executed more than once in global scope. This |
19 |
> provides a minor speed boost when the eclass gets sourced more than |
20 |
> once, and makes sure that any global variables are only set once. |
21 |
|
22 |
OT: inherit() should have already been able to have a non-hacky |
23 |
solution of making sure that eclass files are loaded only once. Bash |
24 |
4.2 has already supported global declaration of variables with -g (in |
25 |
case the flag variable would need to be declared inside a function), |
26 |
and associative arrays with -A. Even older versions of Bash (<4.0) |
27 |
can make use of multiple variables with a common prefix to imitate |
28 |
associative arrays if compatibility is needed. It could just check |
29 |
BASH_VERSINFO if it has to downgrade to a less-efficient method. |
30 |
|
31 |
Besides no longer having to rely on a special `if` block, it probably |
32 |
would also make loading of ebuilds faster since script codes that are |
33 |
referenced multiple times wouldn't have to be re-parsed again and |
34 |
again by bash. It's scary to imagine how it happens in all ebuilds |
35 |
that's read in portage, but maybe repeated loading of eclass files |
36 |
doesn't always happen, who knows. (I think it's still significant |
37 |
even if the dependencies are already cached.) |
38 |
|
39 |
> I think of it as being similar to pre-processor statement you would |
40 |
> find in a C header file; one does not generally indent all the code |
41 |
> within a C header file, because it just introduces a big chunk of |
42 |
> whitespace that does not improve code readability. |
43 |
|
44 |
I did as well, but I'll still prefer to have it indented, because it |
45 |
avoids trying to know what the last lone `fi` is for, if you haven't |
46 |
seen the first `if` condition yet. If they are indented, your mind is |
47 |
automatically set to know that they are within a conditional block, |
48 |
and no surprise happens. Maybe that's not the case if people are |
49 |
already used to seeing those setup, like in eclass files, but I'm not, |
50 |
so it does help improve readability in my case. |
51 |
|
52 |
To be honest I find it painful to see anything inside a block to be |
53 |
not indented, no matter what the reason is. You can say that they |
54 |
look like preprocessors in C, and preprocessors don't make codes |
55 |
indent, but preprocessors are not (functional) codes, and they are |
56 |
naturally recognized to have their own "indentation space" or |
57 |
patterns, unlike the shell's `if`. |
58 |
|
59 |
But anyway, I think I find it understandable now, in the context of |
60 |
eclass files. |
61 |
|
62 |
-- |
63 |
konsolebox |