SKILL Q: "Tidy" Variables Instead of Globals

E

Edward

Guest
I'm amassing quite a collection of global variables (mostly constants)
for some of my routines. So now I'm considering consolidating these
variables either into a global hash or perhaps into some sort of
variable-serving function. Is anyone already familiar with these
kinds of techniques? Can you share a small sample and your views on
the subject?

I'm leaning toward the variable-serving function (e.g.
myGetVar("MPP_w")) solution. However, I'm wondering what kind of
performance/memory hit to expect from setting a bunch of variables up
only to produce the value for one of them at a time. Sure I'll have
some global memory space clear, but this seems like it might be a bad
way to go. Alternatively I've considered having all my variables in a
global hash. I'm guessing this is what most people use to serve
global vars for their various packages.
 
On Mon, 15 Oct 2007 12:23:35 -0700, Edward <edward.dodge@gmail.com> wrote:

I'm amassing quite a collection of global variables (mostly constants)
for some of my routines. So now I'm considering consolidating these
variables either into a global hash or perhaps into some sort of
variable-serving function. Is anyone already familiar with these
kinds of techniques? Can you share a small sample and your views on
the subject?

I'm leaning toward the variable-serving function (e.g.
myGetVar("MPP_w")) solution. However, I'm wondering what kind of
performance/memory hit to expect from setting a bunch of variables up
only to produce the value for one of them at a time. Sure I'll have
some global memory space clear, but this seems like it might be a bad
way to go. Alternatively I've considered having all my variables in a
global hash. I'm guessing this is what most people use to serve
global vars for their various packages.
If you've got global variables, which are constants, then perhaps having some
kind of package to do this might make sense. In SKILL++ you could do:

myGlobalPackage=let((globalHash)
globalHash=makeTable('globals)
procedure(get(var) globalHash[var])
procedure(set(var val) globalHash[var]=val)
`(nil set ,set get ,get)
)

myGlobalPackage->set("const1" 23)
myGlobalPackage->get("const1")

The advantage of the above encapsulation is that you can change the
implementation at a later date. However, this is probably overkill.
Another possibility is just to take advantage of the fact that association
tables can be used with the -> operator. For example:

myGlobalVars=makeTable('globals nil)
myGlobalVars->const1=23
myGlobalVars->const1 => 23

I wouldn't use this for all variables - just for things that really have to be
global.

Regards,

Andrew.


--
Andrew Beckett
Senior Solution Architect
Cadence Design Systems, UK.
 

Welcome to EDABoard.com

Sponsor

Back
Top