The hook
    'see?'  ]# 1 2 3 4
4
works fine...

greg
~krsnadas.org

--

from: 'Pascal Jasmin' via Programming <[email protected]>
to: "[email protected]" <[email protected]>
date: 19 May 2014 22:01
subject: Re: [Jprogramming] Understandable J

is that special code? because its not supposed to work ie:

'see?' # 1 2 3 4
|domain error

The above (] +/ % #) is even a special parsing rule?

>At any rate, the conventions I use help the one who will read my code the 
>most, but I'd still recommend to anyone to avoid long hooks.

--

From: Raul Miller <[email protected]>
To: Programming forum <[email protected]>
Cc:
Sent: Monday, May 19, 2014 11:38:24 PM
Subject: Re: [Jprogramming] Understandable J

That's an interesting line of thought.

>Note that we can take a fork and ensure that we always use its monadic 
>definition by prefixing it with the verb ]

Here's a mean example:
mean=: ] +/ % #

   mean 2 3 5 7
4.25
   'see?' mean 2 3 5 7
4.25

>Now obviously there isn't a lot of need for this kind of thing - we've gone 
>for years (decades?) without anyone complaining about its absence. But it's 
>still kind of neat.

Thanks,
Raul

--

from: 'Pascal Jasmin' via Programming <[email protected]>
to: "[email protected]" <[email protected]>
date: 19 May 2014 20:19
subject: Re: [Jprogramming] Understandable J

Here are some ways to improve readability for me:

lets take,

quicksort=: (($:@(<#[),(=#[),$:@(>#[))({~ ?@#))^:(1<#)

the first step is spacing out the train:

quicksort=: (($:@(<#[) , (=#[) , $:@(>#[)) ({~ ?@#)) ^: (1<#)

>the next step is avoiding the hook that takes a while to find due to all the 
>parens:

quicksort=: (] ($:@(<#[) , (=#[) , $:@(>#[)) ({~ ?@#)) ^: (1<#)

>I find the above superhelpful because the left ] tells me right away that it 
>is a fork. and then automatically all of the references to [ in the pivot verb 
>are actually ones to y argument, and I know that the whole verb is monadic.

>optional, but I think still helpful, is to add whitespace to long parens, and 
>it doesn't hurt to get rid of right hook:

quicksort=: (] ( $:@(<#[) , (=#[) , $:@(>#[) ) (] {~ ?@#)) ^: (1<#)

--

from: Don Kelly <[email protected]>
to: [email protected]
date: 19 May 2014 18:55
subject: Re: [Jprogramming] Understandable J

>Agreed  but both need attention- often the most refined program may be the 
>hardest to read.

--

from: 'Bo Jacoby' via Programming <[email protected]>
reply-to: [email protected]
to: "[email protected]" <[email protected]>
date: 17 May 2014 21:31
subject: Re: [Jprogramming] Understandable J

Improve the program rather than the documentation.

--

from: Don Kelly <[email protected]>
to: [email protected]
date: 17 May 2014 19:49
subject: Re: [Jprogramming] Understandable J

>I find that putting code with lots of explanatory NB.'s  and maybe a how-to  
>paragraph as a noun in a script is essential. This also works for little code 
>snippets than may prove useful in the future (and sometimes with variations 
>listed).  Examples also help.

>This is not only an aid to me, but to others who may use the code. This came 
>from past APL experience where I would look at something I wrote and wondered 
>what I did. Starting from scratch is nice but if the hard work has been done, 
>why do it again

except to improve on  the approach?

There are 2 ways:

>1)intersperse comments within multiline verbs  to help interpretation of the 
>line

>2)provide a noun such as "howN' and example of this is the following 
>definition from an Essay on Newton Raphson where the following is given

 N=: 1 : '- u % u d. 1' (which could be given a better name)

>this could be followed by a series of NB.'s in the script indicating the usage

NB. (_2+*:)N ^:c]xo solves x^2 =2 using c iterations starting form a guess xo
or with more Nb. for more detail.

--

from: robert therriault <[email protected]>
to: [email protected]
date: 15 May 2014 23:36
subject: Re: [Jprogramming] Understandable J

Thanks Raul,

>I am happy with some of the progress that I am making in my projects  (and 
>occasionally programming as well), but I like the poetry of J and in that way 
>part of the challenge is placing the context through the examples. Without 
>that context a poem is just pretty words on a page and a tacit expression 
>without examples may not even reveal its valence.

>I think that there are opportunities in combining good test driven development 
>with the rapid prototyping abilities of J -- but first I am playing with J 
>Labs as a medium of expression, education, art etc.

Cheers, bob

>ps. I appreciate the support for my work. The fact that I am a terrible 
>programmer does not keep me from making terrible programs that explore neat 
>ideas. Life's too short to let a lack of talent hold you back :-)

--

from: Raul Miller <[email protected]>
to: Programming forum <[email protected]>
date: 15 May 2014 23:10
subject: Re: [Jprogramming] Understandable J

>I would not knock "starting from scratch" as a bad thing. Arthur Whitney has 
>been known to do that, for example.

>I think it matters more what you are accomplishing and your ability to make 
>that useful for other people.

Thanks,

--

from: robert therriault <[email protected]>
to: [email protected]
date: 15 May 2014 23:07
subject: Re: [Jprogramming] Understandable J

>I am a terrible programmer, but I have found that including comments that have 
>examples of what the entity should do, are usually enough for me to figure out 
>what is going on.

>Without that ... I usually start from scratch, as that is faster and less 
>frustrating.

I really am terrible at programming.

Cheers, bob

--

from: 'Bo Jacoby' via Programming <[email protected]>
to: "[email protected]" <[email protected]>
date: 15 May 2014 22:52
subject: Re: [Jprogramming] Understandable J

>"how does one write understandable J?" One does not write understandable J! 
>One writes as compactly as possible, and if it needs to be understood it's 
>parts are investigated piece by piece. Understandability is not a property of 
>text, but rather a property of relationship between text and reader. / Bo.

--

from: Don Guinn <[email protected]>
to: Programming forum <[email protected]>
date: 15 May 2014 18:50
subject: Re: [Jprogramming] Understandable J

>What is easy and obvious depends so much on one's background. Several years 
>ago we tried to teach a woman, at the time in her 80's, how to use a Windows 
>computer. Total failure. The real problem was that she could see no use in or 
>reason to use a computer. She had no interest in learning it.

>Anyone who thinks that today's computer technology is intuitive, obvious and 
>easy should go to an old folk's home and try to teach them to use a smart 
>phone. But for a four-year-old. Piece of cake.

--

from: Raul Miller <[email protected]>
to: Programming forum <[email protected]>
date: 15 May 2014 17:10
subject: Re: [Jprogramming] Understandable J

>I am convinced that most code is not understandable to most people, regardless 
>of the language it is written in. When I look at how the computer industry has 
>progressed, I see this more and more. People write huge amounts of code, don't 
>document it very well, then other people use arbitrary bits of it and things 
>sort of just freeze at that point.

>Personally, also, when I read code in any language, I do not feel I really 
>understand it until I see what it does to representative data.

>So clear descriptions, simple data, and good labels are where I would focus 
>most of my efforts in making code readable. And I would also expect that most 
>of my code is going to be unread by most people (and I'll get dinged for 
>utterly random stuff by people who do read it).

>I think the point of readability is: you are going to need to be able to fix 
>it, yourself, when it breaks, so you need to make it readable for yourself. 
>And for that purpose, coming back and trying to read it a month or so after 
>you've written it can be a good exercise.

>Also, I've found that documenting code is a great way of making code simpler. 
>It's quite often the case that it's easier to change the code to be easy to 
>document than it is to document some coding quirks that originally seemed to 
>be a good idea. So if you want readable code, another good thing to do is have 
>a technical writer (or at least someone reasonably literate) work with the 
>programmer to document it for some audience.

>Of course, the most important thing is making sure that it works.

Thanks,

--

from: Kip Murray <[email protected]>
to: "[email protected]" <[email protected]>
date: 15 May 2014 14:23
subject: [Jprogramming] Understandable J

>How does one write understandable J?  I offer my newt adverb below which uses 
>spaces to promote understandability.

>Another technique might be Linda's "bottom up" style of first showing pieces 
>then putting the pieces together.  What are your techniques?  Please 
>illustrate.

>We would like at least to understand our own code when we come back to it!

   NB. Newton's method

   newt =: 1 : 0
t =. y
h =. 1 % 512
whilst. t ~: s do.
   s =. t
   t =. s - +: h * (u s) % (u s + h) - u s - h
   h =. h % 2
end.
t
)
   (2 - *:) newt 2   NB. Find root of 2 - *: near 2
1.41421
   (2 - *:) newt _2  NB. Find a root near _2
_1.41421
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to