Subject: Re: Large vs small functions
From: mslamm@pluto.cc.huji.ac.il (Zvi Lamm)
Date: 16 Feb 1995 16:54:11 GMT
References: <D3Iopu.Bnt@watserv1.uwaterloo.ca> <BEVAN.95Feb10104910@panther.cs.man.ac.uk> <1995Feb11.083959.8428@yrloc2.Tor.Soliton

hui@yrloc2.Tor.Soliton.COM (Roger Hui) writes:

>b. The following function computes the product of the n integers
>pointed to by v; typically, it's used to compute the number
>of elements of an array from its shape (as in the fragment above).
>(It explicitly checks for zeros to avoid integer overflow in
>expressions like  */ 1e9 2e9 0 .)

>I prod(n,v)I n,*v;{I z=1; DO(n,if(!v[i])R 0;); DO(n,z*=v[i];); R z;}

>Recasting the presentation to have one statement per line:

>I prod(n,v)
> I n,*v;
>{
> I z=1;
> DO(n,if(!v[i])R 0;);
> DO(n,z*=v[i];);
> R z;
>}

[ explanation of all the problems in reading the above]

>long prod(n,v)
>    long n;
>    long *v;
>{
>    long i;
>    long z=1;

>    for(i=0; i<n; ++i)
>    {
>        if(!v[i])
>            return 0;
>    }

>    for(i=0; i<n; ++i)
>    {
>        z*=v[i];
>    }
>    return z;
>}

Much more readable!!!

I think the J source is more oriented towards J and APL programmers than
towards C programmers - even though it is written in C.

Being an experienced programmer I can grasp the last version in about a
second, but it takes me much longer to read the original.

This is why I think there is a need for a "reading manual" for the
source. Maybe I will put it in the programming FAQ, or maybe as something
seperate. Any preferances anyone?

--
Ehud Lamm     mslamm@pluto.mscc.huji.ac.il
