If you have a big project and want to split it into modules you are well
adviced to look at locales and if you do want to have globals you could put
them all into one locale and have all your modules use them by fully
qualified names

  GLOBAL1_localeglobal_=.1
  GLOBAL2_localeglobal_=.1
  names_localeglobal_''
GLOBAL1 GLOBAL2


2006/9/11, Ewart Shaw <[EMAIL PROTECTED]>:


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




--
Björn Helgason, Verkfræðingur
Fugl&Fiskur ehf, Þerneyjarsund 23, Box 127
801 Grímsnes ,t-póst: [EMAIL PROTECTED]
Skype: gosiminn, gsm: +3546985532
Landslags og skrúðgarðagerð, gröfuþjónusta
http://groups.google.com/group/J-Programming


Tæknikunnátta höndlar hið flókna, sköpunargáfa er meistari einfaldleikans

góður kennari getur stigið á tær án þess að glansinn fari af skónum
         /|_      .-----------------------------------.
        ,'  .\  /  | Með léttri lund verður        |
    ,--'    _,'   | Dagurinn í dag                     |
   /       /       | Enn betri en gærdagurinn  |
  (   -.  |        `-----------------------------------'
  |     ) |        (\_ _/)
 (`-.  '--.)       (='.'=)
  `. )----'        (")_(")
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to