[REBOL] Re: REBOL] Re: source code layout question
From: carl:cybercraft at: 5-Jan-2002 15:41
On 05-Jan-02, [SunandaDH--aol--com] wrote:
> I also guess a preferred formating style depends largely on what the
> expected lifecycle of the code is. I assume code is a high
> maintenance item, and leave it spaced out to make modifications (in
> my option) easier. As an example, I was never convinced by Carl S's
> "mental reduction" example in Zine/2. He reduces a Style B snippet:
> either (mode) [
> data: find data "Active"
> ][
> data: find data "Passive"
> ]
> to the one-liner:
> data: find data either mode ["Active"]["Passive"]
> Now that may be absolutely necessary in some circumstances where
> memory is tight. But my instinctive reaction was: "Arrghh no! What
> if I then need to perform an additional according to the value of
> 'mode?" The original is much clearer as to where that additional
> code should go.
Well, I was convinced, and I now find the one-line version easy and
natural to read. Also, adding any additional code /is/ simple...
data: find data either mode [a: 1 "Active"][b: 2 "Passive"]
or if you wish...
data: find data either mode [
a: 1
"Active"
][
b: 2
"Passive"
]
What that example shows is the added value a functional language gives
you, another being the ease with which you can capture interim
results of an evaluation. For instance...
data: find data d: either m: mode ["Active"]["Passive"]
would result in 'm holding what's returned by 'mode and 'd holding
either "Active" or "Passive". To do that your way would require
something like this...
m: mode
either m [
d: "Active"
data: find data d
][
d: "Passive"
data: find data d
]
or perhaps more sensibly...
m: mode
either m [
d: "Active"
][
d: "Passive"
]
data: find data d
which cuts out most of the repetition, but even so, I'd still prefer
this...
m: mode
d: either m ["Active"]["Passive"]
data: find data d
and would consider it more readable. (And yes, more readable than the
one-line version, but sometimes capturing interim results within an
expression is very useful, and that was more an example of the
usefulness of a functional language than the line's readability.)
--
Carl Read