From: Jonathan Leighton Date: 2006-01-12T19:09:07+09:00 Subject: Re: Looking up properties and speed On Thu, 2006-01-12 at 11:05 +0900, David Vallner wrote: > Hmm. Accessing the property should be slower, because it involves a > method call. > > > BUT! Quite a few guides on coding style would say temporary variables > should be avoided whenever possible in clean OO code and replaced with > queries (computed property getters). And using a temporary variable only > to cheat the interpreter is plain wrong. Avoid. The speed improvement > you gain will most likely be next to insignificant, and if not, you > still should never optimize without profiling the code first. > > That said, the code you show is more likely to end up refactored as a > method of ``obj'', where you could access the instance variable > directly. A method that only manipulates data on another object indeed > should be a method of that object. > > Suggested reading: Martin Fowler's "Refactoring...", a timeless, and IMO > highly respected classic. > Thanks for the input and explanation. It *was* more a theoretical question than something I was actually considering as general coding practise -- I find it strangely interesting to find out which ways of doing things are faster or slower and why. Anyway, thanks everyone Jon -- Jonathan Leighton http://turnipspatch.com/ | http://jonathanleighton.com/ | http://digital-proof.org/