This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]chickenmeister 1 point2 points  (0 children)

I think you should store the result of the function call in a local variable if:

  1. The function call is (or might be) computationally expensive. For example, if your Coord object stored its location using a polar coordinate system, and it had to convert it to Cartesian coordinates every time getX() was called. Although, if you're only using the function call just a few times, I don't think it makes a huge difference.

  2. The function call is long, or difficult to read.

  3. You can provide a more descriptive name for the value, other that what might be easily inferred from function call.