Readability: Difference between revisions

Jump to navigation Jump to search
601 bytes added ,  06:06, 25 September 2020
Line 2: Line 2:
== Examples ==
== Examples ==
=== Gilman & Rose ===
=== Gilman & Rose ===
In [[Books#APL_.E2.80.95_An_Interactive_Approach|APL an Interactive Approach]], the authors the authors describe the following code, which computes the correlation coefficient, as “almost pornographic”:<!--- Intentionally not syntax coloured --->
In [[Books#APL_.E2.80.95_An_Interactive_Approach|APL an Interactive Approach]], the authors the authors describe the following code, which computes the correlation coefficient, as “almost pornographic”:<!--- Intentionally not syntax coloured --->
:<code>r←(+/x×y)÷((+/(x←x-(+/x)÷⍴x)*2)×+/(y←y-(+/y)÷⍴y)*2)×.5</code>
:<code>r←(+/x×y)÷((+/(x←x-(+/x)÷⍴x)*2)×+/(y←y-(+/y)÷⍴y)*2)×.5</code>
By splitting the expression intro even a moderate number of pieces, a symmetry is revealed:
<pre>yVar←+/(y-(+/y)÷⍴y)*2
xVar←+/(x-(+/x)÷⍴x)*2
r←(+/x×y)÷(xVar×yVar)×0.5</pre>
This also avoids reusing variable names, and thus ensures that the code can be rerun from at any point. The chosen additional variable names are still short, but quite indicative of what they signify ([[wikipedia:variance\]]). Finally, the <source lang=apl inline>.5</source> is expanded to <source lang=apl inline>0.5</source> which helps to clarify that this is a decimal number and not an [[inner product]].
=== IBM ===
=== IBM ===
The [[APL2]] Idiom list includes the following entry:
The [[APL2]] Idiom list includes the following entry:

Navigation menu