Hi, Craig.
I remembered this morning that, as from AppleScript 1.10, there’s a new considering/ignoring attribute for string comparisons: numeric strings. Your original handler code (if it’s only to be run in Tiger or later) could be enclosed in a considering numeric strings block:
set k to {{"Extra Suites", "2.4"}, {"Microsoft Entourage", "1.8"}, {"Safari", "1.3"}, {"Dock", "0.9"}, {"DragThing", "0.3"}, {"lazymousebg", "0.2"}, {"Script Editor", "3.1"}, {"Keychain Scripting", "0.0"}, {"Finder", "0.0"}, {"Finder", "10.10"}, {"Finder", "100.04"}, {"Finder", "100.01"}}
bubblesort(k)
on bubblesort(array)
considering numeric strings
repeat with i from length of array to 2 by -1 --> go backwards
repeat with j from 1 to i - 1 --> go forwards
tell array
if (item j)'s item 2 > (item (j + 1))'s item 2 then
set {item j, item (j + 1)} to {item (j + 1), item j} -- swap
end if
end tell
end repeat
end repeat
end considering
return array
end bubblesort
-->{{"Keychain Scripting", "0.0"}, {"Finder", "0.0"}, {"lazymousebg", "0.2"}, {"DragThing", "0.3"}, {"Dock", "0.9"}, {"Safari", "1.3"}, {"Microsoft Entourage", "1.8"}, {"Extra Suites", "2.4"}, {"Script Editor", "3.1"}, {"Finder", "10.10"}, {"Finder", "100.01"}, {"Finder", "100.04"}}
This seems to be marginally faster (with the test list) than individual coercions to number. It also, of course, removes the necessity for the second item in each list to be coercible to number. But as I said, it’s only available with Tiger so far. Minutely faster still is considering case and numeric strings!
In theory, for greater flexibility, the considering block could enclose the call to the handler rather than being in the handler itself. That way, the same handler could used to sort either considering or ignoring numeric strings. I can’t imagine that would be particularly useful here, though.