Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 20 Jul 2001 21:35:41 +1000 (EST)
From:      Bruce Evans <bde@zeta.org.au>
To:        Ruslan Ermilov <ru@FreeBSD.org>
Cc:        Bruce Evans <bde@FreeBSD.org>, cvs-committers@FreeBSD.org, cvs-all@FreeBSD.org
Subject:   Re: cvs commit: src/share/man/man9 style.9
Message-ID:  <Pine.BSF.4.21.0107202121300.9566-100000@besplex.bde.org>
In-Reply-To: <20010720113310.C30828@sunbay.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Fri, 20 Jul 2001, Ruslan Ermilov wrote:

> What about this block?
> 
> 		if (mylevel == SLC_DEFAULT) {
> 			slctab[(int)func].current.flag = flag;
> 			slctab[(int)func].current.val = val;
> 			flag |= SLC_ACK;
> 		} else if (hislevel == SLC_CANTCHANGE &&
> 		    mylevel == SLC_CANTCHANGE) {
> 		    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 			flag &= ~SLC_LEVELBITS;
> 			flag |= SLC_NOSUPPORT;
> 			slctab[(int)func].current.flag = flag;
> 		}
> 
> This is using style(9)'s second-level of four indents rule.
> But, strictly speaking, `else if' is not an operator, this
> is `else' operator followed by the `if' operator.  So if we
> would use the second-level indent of four spaces relatively
> to the `if' operator, we would get:

I would call both `if' and `else' keywords, not operators.

> 		if (mylevel == SLC_DEFAULT) {
> 			slctab[(int)func].current.flag = flag;
> 			slctab[(int)func].current.val = val;
> 			flag |= SLC_ACK;
> 		} else if (hislevel == SLC_CANTCHANGE &&
> 			   mylevel == SLC_CANTCHANGE) {
> 			flag &= ~SLC_LEVELBITS;
> 			flag |= SLC_NOSUPPORT;
> 			slctab[(int)func].current.flag = flag;
> 		}
> 
> Which is much better, no?

No :-).

> Hell, but then, I guess, we would need
> to indent lines within `else if' block relative to `if' as well.

Yes, only of the main advantages of the 4-char continuation indent rule is
that it doesn't depend on the context.  If the continuation indent depended
on the context, then you would get continuation indents all over the place
and need complicated rules to make them deterministic.

I think, strictly speaking, `if' after `else' begins a new clause so it needs
a first-level indent:

	if (...) {
		...
	} else {
		if (...) {
			...
		} else {
			if (...) {
				...
			}
		}
	}

but `else if' is idiomatic -- no one writes an else-if ladder like the above.
Anyway, the continuation indent rule is at the lexical level, so it doesn't
apply to `else if'.

Bruce


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe cvs-all" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.21.0107202121300.9566-100000>