This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

use of temporary variable inside method  RSS feed

 
Naty wills
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have a doubt in using a temporary variable defined inside a method.
I am defining a temporay String object inside my method and initializing with the value returned from a called function and then again I am using it as parameter in my another calling function. Will be there any performance issues?? Whats the best of doing it. Should I use temporary variable or not?
Example ::

String temp = object.generateMapping(map);
object1.addValues(temp);

any suggestions are welcomed
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Believe me you really do not need to think about it!!!
Just go ahead and do what you think will increase code readability.

Remember - "Premature optimization is a root of all evils"
 
Tim Holloway
Bartender
Posts: 18662
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The trip from source to final executable is fairly complex. It's not uncommon for 7 layers or more of processing to pass over the code as it makes its way from human-readable source to lexical token streams to abstract syntax trees and on down the line.

As part of this process, a lot of things get pushed up, pulled down, shifted around, created and destroyed. Temporary variables are one of the prime targets. So don't try to optimize code based on temporary variable usage - it's pointless.

The only exception I'll make is that if you are running with optimization switched off, some artifacts may remain to assist a debugger when it wants to print those intermediate values. However, if performance at the code level is critical, you should turn optimization on.
 
Naty wills
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the Suggestions
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!