the keys of myArray
ambassador at fourthworld.com
Fri Sep 8 11:31:02 EDT 2006
>> There may be other ways to handle this, although if using the built-in
>> sort command will do what you need it's reasonably efficient. It's only
>> one line of code -- was it causing a problem in your script?
> it's not causing any problem in my script.
> again, I was just wondering about any logic behind the keys order...
> actually, there's only 1 situation I can imagine in which it could be
> useful to know in advance in which order keys would be output :
> in heavy math treatments with loops in which arrays values & keys
> are needed for further processing, many lines of code (sort commands)
> would be saved and scripts sped up significantly...
If you're up for it feel free to post the code and the folks here can
see what can be done to optimize it. I've been very impressed with the
results of that sort of group effort here and on the MC list, and I've
learned a lot from those exercises.
A recent example:
The script colorization algorithm in the MC IDE was quite slow, taking
more than 30 seconds to colorize long scripts like libURL on my 1GHz
Mac. Those of us who volunteer to work on the MC IDE were looking for
ways to speed that up, but we considered caching the htmlText a last
resort since that workaround adds its own difficulties (increases object
size, adds stuff to the user's custom properties, and introduces
additional complexity into the code base, requiring overhead to maintain
and keep it in synch).
More importantly, this type of algorithm is likely useful in other
people's apps, so coming up with a way to do this efficiently without
caching would open doors for Rev's customers, turning what was a
annoyance and a support expense into an inspiring liberation.
I don't know much, but I know there are a lot of people in this
community much smarter than I am, so I posted a note to the MC IDE list
to ask for help in optimizing this.
We had four people come up with a variety of alternatives, all of which
were several orders of magnitude faster and none of which required caching.
The end result is that there's now a script colorization algorithm
available which can do libURL in about a second -- and that's on a slow
This exercise not only gave us a very valuable algorithm, but more
importantly reinforced the value of leveraging the collective wisdom of
the community when facing a difficult challenge.
After that experience I'm sold: as soon as I come across a task that I
think is impossible, I invite others to look it over and I always learn
a lot in the process. And usually the code gets both smaller and faster
as well. :)
> BTW here's a suggestion for a slight improvement of the "keys" function :
> get the numKeys of myArray --> outputs the keys in numeric order
> get the alphaKeys of myArray --> outputs the keys in alphabetic order
Those might be handy indeed -- have you submitted those requests to BZ?
Managing Editor, revJournal
Rev tips, tutorials and more: http://www.revJournal.com
More information about the Use-livecode