[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: coding style



here's how i would indent that, based partially on a suggestion from
steve@endgame.gsfc.nasa.gov.  note that es' if statement actually
supports an arbitrary length chain of else-if tests, a la scheme's cond.

rc code:
> if (~ $TERM () || ~ $TERM '') {
> 	TERM = unknown
> } else if (~ $TERM *' '*) {
> 	t = () {
> 		eval 't = (' $TERM ')'
> 		TERM = $t(1)^-^$t(2)
> 	}
> } else if (~ $TERM *vt520) {
> 	TERM = vt52
> }

proposed es code:  (this shouldn't work because the %or does not
cover multiple lines)
> %or     {%and {~ $TERM () || ~ $TERM ''} {TERM = unknown}}
> 	{%and {~ $TERM *' '*} {
> 		let (t = ()) {
> 			eval 't = (' $TERM ')'
> 			TERM = $t(1)^-^$t(2)
> 		}
> 	}}
> 	{%and {~ $TERM *vt520} {$TERM = vt52}}

my version:
	if (
		{~ $#TERM 0 || ~ $TERM ''}	{ TERM = unknown }
		{~ $TERM *' '*}			{ TERM = <>{%flatten - <>{%split ' ' $TERM}} }
		{~ $TERM *vt520}		{ TERM = vt52 }
	)

steve's suggestion, which i love & endorse is to take advantage of the fact that
within parens, newlines are treated just as spaces, so we don't need to use the
hanging braces (open brace at end of line) to continue a line.  this could be
written even more lispish as
	(if
		...
	)
but i think that that obfuscates rather than elucidates.

two notes:  (1) i recommend against using %or and %and unless you really want them.
if is usually more clear.  i tend to try to stay away from using % commands except
when redefining them or a few other special purposes.  && and || work in es, and
%or and %and are mainly around to support that funky syntax.  (2) i'm not sure
that my TERM setting code above does exactly what yours did---i tend to not like
using eval.  here i go against what i recommended earlier this paragraph and
used %flatten and %split, because there is no syntax to access them directly.