[futurebasic] Re: [FB] Where are my glasses?

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : March 2012 : Group Archive : Group : All Groups

From: Brian S <fblistserve@...>
Date: Tue, 20 Mar 2012 22:33:26 -0700
On Mar 20, 2012, at 6:44 PM, Ted Spencer wrote:

> 
> On 20 Mar, 2012, at 11:42 AM, Brian S wrote:
> 
>> 
>> First a story: one of my clients was using globals and accessing them( including modifying their contents ) within many local FNs. One day ( after reading a tutorial on the FB5 web page ) he discovered it was possible to pass the data by reference ( i.e. by pointer ) to each FN that needed it.
> 
> That's easy to follow, but isn't that pointer pointing to something that looks and smells like a global array?
In this case no. The FN reads data from a file, does some calculations and passes the calculated data to another FN ( which may or may not pass it again to another fn ). At some point in the process the data is written ( this is selective data not an entire file ) to a file. This processing made sense for this particular app. Prior to implementing data passing the data was all held in global vars ( which were all in an dynamic array of records ). 


> 
>> By passing data into the FN, the FN could then be used for different sets of data and wasn’t coupled tightly to the global vars it was manipulating before the change to using passed data.
> 
> This is simple data: a series of voltages (up to 5000 of them) are read from a file or directly from a connected A/D convertor. They get processed to remove noise, all peaks and valleys are found and used to plot an envelope around the waveform, and there's a time marker for each reading.
> 
> dim as integer voltage(5,6,5000)
> _timeMarker = 0
> _iVolt = 1
> _fiveAvg = 2
> _tenAvg = 3
> _PeakValley = 4
> 
> The first two come from the file or A/D, and the next three (and probably more) are calculated. The second dimension of the array is for the necessary 6 instances of test cycles that complete the job; they come in as the day unfolds. The whole works is printed/plotted and dear knows what else.
> 
> This thing is a global now. Could it be anything else?
> 
> FN FiddleWithVoltage (voltage(x,y,z)) //??
'--------------- this is OTTOMH and just shows how to pass arrays -----------
local fn DoSomeThing( someData(5,6,5000 ) as SInt32 )
'~'1
someData( 1, 1, 2000 ) = 3456 // process the array
end fn

local fn GetSomeData
'~'1
dim as SInt32  myData( 5, 6, 5000 )

// possibly read data into myData - could be some or all

fn DoSomeThing( myData(0,0,0) )
print myData( 1, 1, 2000 ) // should be 3456
// possibly save to disk
end fn

fn GetSomeData// for example, could pass FSRef to a file.
RunApplicationEventLoop
'---------------



>> 
>> Another possible tool is to access the data when needed and not try to create a global array of everything the code might ever need. An old pattern typically would ( at program initialization ) read a data file into a global array, process the data and then write to a file at program termination.
> 
> That, I suspect, is the answer to the above question...

Possibly. The processing needs to be reviewed by the programmer to determine what is possible. For example, it sounds like the data is collected gradually but it might be processed immediately before all data is collected ( or maybe all data must be collected before any or all calculations are performed). Globals aren't automatically bad and can be used successfully with a large dose of discipline/discretion ( RP’s posts on this topic are well worth reading ) but can easily create an unfathomable/unmaintainable mess.  


Brian S