I love strong typed languages. Languages that require you to define all variables before use. They save me from myself, or, from my attrocious spelling. I was working on LibraryFind, OSU’s opensource metasearch service, three days ago making a few tweaks and changes. One of the things that this tool has that is somewhat researchy — is this idea of caching all results and how that cache gets reutilized in different sessions. Anyway, I was making a few changes to the following lines:
#======================================================
# Check to see if data was cached -- if it is load
#======================================================
if _search_id != nil
_lxml = CachedSearch.retrieve_metadata(_search_id, _collect.id, _max.to_i)
if _xml != nil
if _lxml.status == LIBRARYFIND_CACHE_OK
if _lxml.data != nil
_lrecord = _objRec.unpack_cache(_lxml.data, _max.to_i)
_results_count = _results_count + _lrecord.length
record = record.concat(_lrecord)
is_in_cache = true
else
is_in_cache = true
end
elsif _lxml.status == LIBRARYFIND_CACHE_EMPTY
is_in_cache = true
end
end
end
See what I did? I’m sure you do. However, I didn’t until last night when I thought that the caching service was running really slow. So I looked in the code, and found my problem. A typo. It should have looked like:
#======================================================
# Check to see if data was cached -- if it is load
#======================================================
if _search_id != nil
_lxml = CachedSearch.retrieve_metadata(_search_id, _collect.id, _max.to_i)
if _lxml != nil
if _lxml.status == LIBRARYFIND_CACHE_OK
if _lxml.data != nil
_lrecord = _objRec.unpack_cache(_lxml.data, _max.to_i)
_results_count = _results_count + _lrecord.length
record = record.concat(_lrecord)
is_in_cache = true
else
is_in_cache = true
end
elsif _lxml.status == LIBRARYFIND_CACHE_EMPTY
is_in_cache = true
end
end
end
Since Ruby, like many scripting languages, happily created variables for you, I didn’t notice it. And since the program kept running — abiet, more slowly — it didn’t dawn on me that I’d caused a boo-boo. It wasn’t until last night, 2 days later, that I found it while doing a code audit. A practice I have when dealing with scripting languages is to audit modified code weekly to inventory the life of each variable/process. It’s something I do mostly as a way to eliminate variable useage — but in this case, it helped me find this problem. Ack.
–TR
