Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: REBOL] Re: source code layout question

From: carl:cybercraft at: 6-Jan-2002 13:34

On 05-Jan-02, [SunandaDH--aol--com] wrote:
> Hi Carl, > Sunanda: >>> 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. > Carl: >> 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"] > It's easy to think up simple changes that would make the one-liner > difficult to maintain: > If Mode is True position Data at "Active", unless Mean is 5, in > which case leave Data's position unchanged > If Mode is False position data at "Passive" unless Median is unset, > in which case also unset Data > Or > If Mode is True and Data is a series position Data at "Active"; but > if Data is an integer, set it to zero. > The problem is that the one-liner makes two assumptions: first that > Data is a series; and second that the result of manipulating it > should be a change in its position). The longer code need make > neither of these assumptions. > Whether those assumptions are reasonable or not is not something we > can't tell from such an artificial example. But I do try to write > code remembering that maintaining it is much harder than writing it. > So if I've been as clever as I possibly can in distilling it down to > one-liners at time of writing, my successors (including an older me) > have little chance of maintaining it.
It's all a question of how readable the one-liner ends up being. I'd say to a REBOL programmer that... result: either whatever-1 [whatever-2][whatever-3] is as readable as... either whatever-1 [ result: whatever-2 ][ result: whatever-3 ] and probably more readable in fact. And as long as the one-liners are readable and hence can be converted into a five-liner with next to no thought, you have two payoffs due to a more efficient program and code that occupies a lot less lines. Look at the above two example: With the one-liner your eyes only need to scan left and right to understand it, (like a quick scan of the horizon), while with the five-liner our eyes are jumping back and forth vertically as well as horizontally. Humans are designed for reading one-liners... (: But I'm serious about the above, and the "left-right scanning" may be why Joel's... either whatever-1 [ result: whatever-2] [ result: whatever-3] seems so attractive. Having the blocks all on one line where possible is nice.
> Maybe what we need is not just a prettyprinter.r but also an > optimiser.r. That can produce runtime code which is as densely > one-lined as possible while still functionally equivalent to the > original. Any takers?
No, in that I would think it's probably impossible with REBOL. For instance, how would you optomize 'blk to allow for a later... change blk whatever Your "code" from REBOL's point of view is all just data, remember. -- Carl Read