Hello again all.

I've been working away on a (large, complex) software package,
and have a question on programming style.  This stems from
a recent post I made to  comp.lang.apl  about niladic functions:


========== (original query) ==========

>   I used the APL niladic function to generate
>tutorials in several versions of APL. When J
>came out I was planning to do the same, but
>was unable to do so because J does not support
>niladic functions.

============ (my response) ===========

You can write a monadic function  fun  say that ignores its argument,
and call it in J with
   fun''

I mainly use niladic functions to return globals, for example
   setpc=: 3 : 'PENCOL=: y'   NB. usually more complex than this!
   getpc=: 3 : 'PENCOL'   NB. again may be more complex
                          NB. e.g. return  0 0 0  if  PENCOL undefined
      ...
   p=. getpc''   NB. pen colour
      ...

As a side-effect of the "idiom"  fun''  it's then easy for me
to check when I may be using globals, just by searching for  '' .
This technique makes development less error-prone, at least for me
- for example, if (when?) I decide to change  PENCOL  to be a stack.

========== (further response) ==========

Someone (Markus Triska) then replied saying that
"Passing PENCOL to all functions using it is even less error-prone"

========== (end of extracts) ==========


My experience has been different from Markus's: I know if a
particular function needs access to PENCOL, but keeping track of
"all functions using it" would be a nightmare, particularly in the
development stage (& I expect the development stage to last forever).
I've also found my approach useful whether or not I'm using J's
object-oriented features.

Has anyone any comments?  How do other people avoid being strangled
by spaghetti code? (I'm talking several hundred k of .ijs scripts)

        Regards, Ewart

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to