Record Best Practice Trivia

I’m having a five double espresso OCD moment…

When passing a record as a parameter to a handler, is there any difference between these two approaches, other than one’s aesthetic preference?

set widget to {thePrice:0.29, theColor:"puce"}

on Fussy_Way(widget)
    set thePrice to thePrice of widget
    --reference thePrice several times
end One_Way

on Lazy_Way(widget)
    thePrice of widget
    --several times
end Another_Way

Generally, it takes less time to retrieve a value from a variable than to get it from an object. So if you’re going to need to use a value from an object several times, it’s more efficient to get it from the object just once, assign it to a variable, and then read it from the variable several times, than it is to get it from the object several times. But where the object’s a one-dimensional AppleScript record like the one in your example, you’re unlikely to notice any difference unless “several” really is a lot!

Thanks for the confirmation. This is the sort of thing I worry about at 3:00 am when I’m tired of dreading death and other aspects of the human condition. :kissing_cat:

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.