Roger is always to be listened to.
On this point he (and the last 75 years) of programmers
(and the last 5000 years of mathematicins)
is correct.
Puling all globals into a single structure to pass is the oldest echnique
around,
and works resonably well:
you can call this the dictionary approach: acknowledge that you use one.
I once had a naive PL/1 programmer ask if files were IO ... (sigh)
The simple point of view was to ask if the data was
inside the program or
outside it
Which worked until a programmer some decades ago invented the
large static data sructure intialized to values ...
A tale told tall by Ed Yourdon while I as employed at YOurdon, in. goes as
follows:
A large military contrantor programmed for missile launches in the
Pacific
Accuracy is a fairly important concern
So as to miss the large populated islands there
So the program had a large number of geosat coordinates for them in it
Such as Oahu, Maui, tc.
And they got the program to working
LOOP
BUT: they got a request a few weeks later to move the location a
SMALLAMOUNT
SO: they modified the code
Andlaunched the missiles more accurately avoidng the islands
And everryone was happy
SMALLAMOUNT *= FRACTIONLESSTHANONE
POOL
For ever and ever ..
ANyone guess what was happening? ..
The APollo X mission had planted a laser reflector on the moon
And everyone in the US Geodesic Survey was busily locating
continents and islands
eversomuchmoreso accurately.
After iteration N, using Jovial, they finally did what they sould have done:
Put the costnts into a file and rea them in.
Which is why macro header files got to be used for all constants.
Including zero and one for incrementalling.
And then a programmer invented two values ina single field (hybrid
coupling)
And then command lne arguments (flags, name/value pairs, names, etc.)
And then a programmer invented databass wth their alternate way of
storing accesing, representing, and using data.
See the progression? Generalize to the last drop first;
THEN fix it.
ANd then a programmer invented structurng engines, to do all this fixing on
control
and data too
automatically.
I had the pleasure of emai; corresponding from a guy in South Africa
who used recurson to structure control goto's and worse
into structured loops with break/continue
and generalized it into functions with return values
at the appropriate points
When? Ahhh... 1979 ...
The IS/IT industry does not like code to be clean and work forever:
Microswift cannot sell DoItAllware v2.
Side kvetch: THis also appllies to such things a character code set
ordering tables
sucn as ANSI or ISO-8859-1 and o on.
WHich J itself has fixed in it.
But, as programmers like to point out:
it is just so difficult to get these thnigs FIXED afterwards ...
(Small bronx cheer: even those who teach clean programming occassionally
glitch up).
Cheers.
On 9/13/06, Jim Russell <[EMAIL PROTECTED]> wrote:
Globals have always been a "code smell" red flag to me. And if Roger
hadn't said it, I'd sugest passing an object or a struct or whatever
else is available. OK, Roger can do lots of things that the rest of us
can't, but everyone else ought to avoid globals like the plague.
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Roger Hui
Sent: Monday, September 11, 2006 1:13 PM
To: Programming forum
Subject: Re: [Jprogramming] Developing large projects
I have participated in projects in which there are
hundreds of globals. Passing all of them as
arguments would be really complicated.
On the other hand, there have been a few times when
I got burned as where f called g and g changed a
global which then wrecked things for f . I solved
the problem as follows:
g=: 3 : 0
old=. global
global=: new
blah blah blah
global=: old
result
)
----- Original Message -----
From: Ewart Shaw <[EMAIL PROTECTED]>
Date: Monday, September 11, 2006 5:29 am
Subject: [Jprogramming] Developing large projects
> 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)
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
--
--
Roy A. Crabtree
UNC '76 gaa.lifer#11086
Room 207 Studio Plus
123 East McCullough Drive
Charlotte, NC 28262-3306
336-340-1304 (office/home/cell/vmail)
704-510-0108x7404 (voicemail residence)
[EMAIL PROTECTED]
[EMAIL PROTECTED]
[EMAIL PROTECTED]
http://www.authorsden.com/royacrabtree
http://skyscraper.fortunecity.com/activex/720/resume/full.doc
--
(c) RAC/IP, ARE,PRO,PAST
(Copyright) Roy Andrew Crabtree/In Perpetuity
All Rights/Reserved Explicitly
Public Reuse Only
Profits Always Safe Traded
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm