had a thought earlier today related to structures as return values...
When I run into situations where I want a function to modify multiple
values, I tend to add those values as parameters, and pass them by VAR
then let the function modify them.
This has a few side effects (some good, some bad)...
not intuitive, you can't tell that the assign is happening simply by
looking at the function call.
if the function doesn't return a value, you find yourself using
MvEVAL's, which just don't seem right.
the function can still return a value, which I tend to use as the
'l.ok' success/fail value.
Now I've been using these approaches for some time. Part of the
reason for that, was a speed issue. It seemed that when you had very
large structures, the code ran faster (uncompiled) if you passed them
by var instead of passing them back as a return value. I'm not sure
whether this is still an issue or not, and should probably run some
tests to find out.
Assuming speed is no longer an issue (compiled at least), I'm thinking
of changing it to structured return values. Dunno why it never
crossed my mind, and not sure how well it would work, but I'm thinking
if I use some standard naming convention, it could work.
Can still return an 'ok' value, just as a branch:
l.ret:ok
If it's ok, stuff any data you have on a data branch:
l.ret:data
If you have errors, you can stick them on independent branches --
which allows you to track multiple errors, and/or respond to different
errors different ways.
l.ret:error:MvOpen
l.ret:error:EOF
l.ret:error:Fexists
l.ret:error:DataEntry
It may also pay to make it a structured array, due to miva's lack of
'reflection' (ie: not easy to ask a structure "what branches do you
have?" - at least not in 4.x and under).
The error branch is the beauty of it, as it's let's you seperate error
handling from the core functions. All they do is report the error,
it's up to the calling function to decide what to do - which could
include ignoring them. Of course, that does mean the burden shifts,
but that can be handled with some generic error handling (which can
vary by app, or by function call).
In Merchant's db.mv code, there are a lot of functions that can't be
used 'flexibly' because they cause the script to error out.=20
Sometimes... "Category_Find_Code" is just a 'check', but if I need to
check to see if a category code exists, I can't use that function due
to it's hard coded error check.
anyway, just thinking out loud, thought I'd share it.
--=20
Bill Guindon (aka aGorilla)
Comment