From: Alec Cawley <alec@cawley.demon.co.uk>
Newsgroups: comp.editors,comp.sys.transputer
Subject: Re: Folding editors
Date: Fri, 30 Oct 1998 17:44:35 +0000
Organization: Lost in the Wilderness
Distribution: inet
Message-Id: <QuruoDADsfO2Ewhc@cawley.demon.co.uk>
References: <36374B57.168B9492@pact.srf.ac.uk>
    <71aj0c$oc$1@fangorn.moria.de> <6r1znq7264.fsf@belhaven.spider.com>
    <3639BEFD.2CC25E3C@esgem.com> <6r4ssm59ay.fsf@belhaven.spider.com>
Mime-Version: 1.0
Xref: ukc comp.editors:32001 comp.sys.transputer:8891


In article <6r4ssm59ay.fsf@belhaven.spider.com>, Iain A F Fleming
<iainf@spider.com> writes
>
>The entity calling itself Stephen Maudsley wrote:
>> 
>>  Iain A F Fleming wrote:
>>
>>  > folding is evil
>> 
>>  Certainly I've seen code where scoping of variables has been so convoluted
>>  that it was unmaintainable.
>
>Mainly that, and the allied fact that it allows large blocks of (often
>conditional) code to be folded away rather than being split off into
>subroutines/functions.
>
>Programs composed of small numbers of large functions with complex control
>flow tend to be less comprehensible that a large number of small functions.
>
>Folding encourages the hack-it-and-see incremental mentality.

My experience is the opposite. I have had modules which had essentially
got out of control, and were made comprehensible by folding. 

I go the other way around, if anything. Programs composed of large
numbers of functions can become incomprehensibly fragmented. Folding up
groups of related functions can reduce fragmentation. I particularly
value folding at the top level: my whole module fits on one screen and
reveals itself to consist of maybe a dozen classes. Each of those
classes can then be expanded if necessary. Without folding, I can see no
way that I can overview a whole module. I see folding, thus employed, as
a merging rather than a splitting tool.

Folding should never conceal control flow - that is simply abuse of a
tool, like using a chisel as a screwdriver. I find that I can organise
my code such that I can nearly always see the whole of flow of a system
*at a particular level* on a 60 line screen. On such a display, all
closed folds would be true "black boxes". Whether such black box is
inline code or a procedure call is, IMHO, irrelevant.

As a related thought, it seems to me that there is an opportunity for
using folding as a metric of code quality. It seems to me that variables
should not be affected at many levels of a program: a high level
variable should not be tweaked many levels down. If a module is "fully"
folded, the number of folds which have to be opened to reveal all write
accesses to a variable would, IMO, be related to the "dangerousness" of
that variable.

Returning to the original question, I use a folding editor at work (FED)
written for by a colleague for X-Windows. I will ask him if he is
willing to release it. It improves somewhat on F by handling multiple
files, macros, colouring folds etc.

-- 
Alec Cawley

